0

Tab Activity (たとえば A) に 2 つのタブがあります。
タブ1は何かを示しています(ここでは重要ではありません)。
タブ 2 は、SimpleCursorAdapter(WORKS PERFECT) を使用して SQLite データベースに接続された ListView を示しています。
ここで、タブ 2 の LIST 内の項目をクリックします。これにより、別のアクティビティ (たとえば B) に移動します。
アクティビティ B からアクティビティ A (タブ付きアクティビティ) に戻ると、
そこに ListView が表示されません。タブ 2 は空です。

何をすべきか?logcat で
"ERROR/Cursor(8736): Invalid statement in fillWindow()" が表示されるため、コードのカーソル アダプタ部分も確認してください。

TAB 2のアクティビティ(javaファイル)です。

public class ViewAll extends Activity implements OnItemClickListener {
TextView selection ;
Cursor cursor;
ListView lv1;

@Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

        setContentView(R.layout.bday_list);
       DatabaseHelp dbHelp = new DatabaseHelp(getApplicationContext());
       Log.d("holla", "after database open!");
       lv1= (ListView)findViewById(R.id.List_of_bday);


       dbHelp.open();
        cursor =dbHelp.fetchAllContacts();
         Log.d("DOR DOR",cursor.getCount()+"");
        startManagingCursor(cursor);

                    // the desired columns to be bound
                    String[] columns = new String[] {DatabaseHelp.KEY_NAME, DatabaseHelp.KEY_DATE };
                    // the XML defined views which the data will be bound to
                    int[] to = new int[] { R.id.tv_name, R.id.tv_date };

                   // create the adapter using the cursor pointing to the desired data as well as the layout information
                    SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.list_each_row, cursor, columns, to);
                    // set this adapter as your ListActivity's adapter
                    lv1.setAdapter(mAdapter);

                   dbHelp.close();
lv1.setOnItemClickListener(this);

               }


    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
        // TODO Auto-generated method stub
        Toast.makeText(this, "clicked "+arg2, Toast.LENGTH_SHORT).show();
        Intent i=new Intent(this,ViewOne.class);
        startActivity(i);

    }}    

これはTABBEd ACTIVITYのコードです:-

public class Today extends TabActivity {
    @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
    Resources res=getResources();
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, TodayFinal.class);


    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("today").setIndicator("View Today's Birthday",res.getDrawable(R.drawable.icon)).setContent(intent);

    tabHost.addTab(spec);

    // Do the same for the other tabs
    intent = new Intent().setClass(this, ViewAll.class);
//THIS TAKES YOU TO THE ABOVE MENTIONED ACTIVITY(TAB 2)

      spec = tabHost.newTabSpec("all").setIndicator("View All",
                      res.getDrawable(R.drawable.icon))
                  .setContent(intent);


    tabHost.addTab(spec);



}
4

1 に答える 1

1

dbHelp.close();アダプタを設定してから呼び出します。getViewただし、すべての呼び出しでカーソルを使用するため、カーソル アダプターが正常に動作するには、db 接続が開いている必要があります。閉じる db 呼び出しを に移動しますonDestroy。または、開いてアダプタをセットしonStart、閉じてから挿入しonStopます。

于 2011-08-16T14:21:18.443 に答える