English 中文(简体)
Android 不要订购数据
原标题:Android SQL query not ordering data

我写了一只小roid子, gr一些数据,并在清单中显示。

我想按顺序排列名单(无问题)。 但是,当我增列一个新项目时,即使意见/申请重载,它仍停留在名单的底层。 看来,唯一正在分类的数据是“Create()”数据库方法中设定的条目。

我不敢肯定的是,通过显示你从主要配制班子上跳出的蒸气球,可以开出哪部法规,但一只。

数据库建设问题:

    private static final String DATABASE_CREATE =
    "create table "+ DATABASE_TABLE
    + "("
    + FIELD_ROWID+" integer primary key autoincrement, "
    + FIELD_NAME +" varchar(30) not null, " + FIELD_TELEPHONE + " varchar(20) not null, " 
    + FIELD_ADDRESS + " text not null,"
    + FIELD_URL + " varchar(255) not null);";

获取数据的功能:

    public Cursor getRestaurants() 
{
 Cursor result = null;
 try{
  result = db.query(DATABASE_TABLE, new String[] {FIELD_ROWID, FIELD_NAME}, null, null, null, null, FIELD_NAME+" ASC");
 }
 catch (Exception e)
 {
  Log.v("applog", e.getMessage());
 }
 return result;
}

这里是主要方法的灯塔。 在这里,你可以看到,我指的是上文所述的获得者的职能。 我对数据为何没有分类感到迷惑。

任何建议都得到高度赞赏。 提前感谢。

public class Assignment2 extends ListActivity {

 // Set up some global variables. 
 private static final int ADD_NEW_ID = Menu.FIRST;
 private static final int CLOSE_APP_ID = ADD_NEW_ID+1;
 private final DBAdapter db = new DBAdapter(this);
 private static CursorAdapter curAdapter = null;
 private static Cursor rawData = null;
 @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        db.open(); // Open connection to restaurant db.

     rawData = db.getRestaurants();
     Log.v("applog", rawData.getCount()+" Restaurants loaded from DB.");

     if(rawData.getCount() == 0)
     {
      Toast.makeText(getApplicationContext(), "No restaurants found.", Toast.LENGTH_SHORT).show();
     }
     try
     {
      /* The following two arrays are used to map DB fields to ListView items
       * From a custom layout file.
       */
      // Array of db fields to be used when converting cursor to ListView
            String[] strFields = { "name", BaseColumns._ID };
            // Array of listview id s to be used when populating the ListView
            int[] intFields = { R.id.first };

            curAdapter = new SimpleCursorAdapter(this, R.layout.row, rawData, strFields, intFields);
     }
     catch (Exception e)
     { 
      Log.v("applog", e.getMessage()); 
     }  

     // Apply the converter cursor to the current ListView
     setListAdapter(curAdapter);
        db.close(); // Close connection to restaurant db.
最佳回答

并非确切地说,你的问题是什么,但是,在我从我的新数据获得反馈时,我完全看不出这些法典。

        if(cursor!=null)cursor.requery();
        adapter.notifyDataSetChanged();

希望这将解决你的问题。

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签