0

こんにちは、私はコードの問題を抱えていません。なぜなら、それを行う方法についてまだ何も考えていないからです。私の質問は:

ListView作成したActivityがあり、これで新しいレイアウトを表示しListAdapterたい.ActivityListView

なぜ同じ活動を?

  • 私は自分のものを保持しOnItemClickListener、完全に機能するリストを持ちたいからです。

なぜリストしたいのですか?

  • UIアプリの表示を改善したいからです。

Activityそれを含む新しいレイアウトで別のものを呼び出すとListViewListViewリストの内容を取得するアクティビティがないため、空になります。

4

2 に答える 2

0

では... ユーザー インタラクションの後に、同じアクティビティで異なるビューを表示したいですか? おそらくViewFlipperが役立つかもしれません。

于 2012-05-04T00:16:25.847 に答える
0

Androidの仕組みを誤解していると思います...

複数のリストビューで複数のアクティビティを使用できます。リストビューはすべて同じレイアウトを使用することも、異なるレイアウトを使用することもできます。また、それぞれ独自の onItemClickListener を持つこともできます。

私のプロジェクトの例:

public class BrowseSetups extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mDBHelper = new DBAdapter(this);
        mDBHelper.open(DBAdapter.MAIN_DATABASE_NAME, DBAdapter.MAIN_DATABASE_VERSION);
        setupsCursor = mDBHelper.fetchSearchSetups(find, column);
        this.startManagingCursor(setupsCursor);
        String[] from = new String[] { DBAdapter.SETUP_PART };
        int[] to = new int[] { R.id.ListItem1 };
        SimpleCursorAdapter tools = new SimpleCursorAdapter(this,
            R.layout.listlayout, setupsCursor, from, to);
        setListAdapter(tools);
}
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        setupsCursor.moveToPosition(position);
        Intent myIntent = new Intent(BrowseSetups.this, BrowseTools.class);
        BrowseSetups.this.startActivity(myIntent);
    }
}

public class BrowseTools extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mDBHelper = new DBAdapter(this);
    mDBHelper.open(DBAdapter.MAIN_DATABASE_NAME, DBAdapter.MAIN_DATABASE_VERSION);
    toolsCursor = mDBHelper.fetchAllTools();
    this.startManagingCursor(toolsCursor);
    String[] from = new String[] { DBAdapter.TOOL_ROWID,
            DBAdapter.TOOL_DESCRIPTION };
    int[] to = new int[] { R.id.ListItem1, R.id.ListItem2 };
    SimpleCursorAdapter tools = new SimpleCursorAdapter(this,
            R.layout.listlayoutdouble, toolsCursor, from, to);
    setListAdapter(tools);
    }
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    toolsCursor.moveToPosition(position);
    String Tool = "Tool #: " + id;
    String Description = "Description: "
            + toolsCursor.getString(toolsCursor
                    .getColumnIndex(DBAdapter.TOOL_DESCRIPTION));
    String Location = "Location: "
            + toolsCursor.getString(toolsCursor
                    .getColumnIndex(DBAdapter.TOOL_LOCATION));
    AlertDialog locationAlert = new AlertDialog.Builder(this).create();
    locationAlert.setTitle("Tool Information");
    locationAlert.setMessage(Tool + "\n" + Description + "\n" + Location);
    locationAlert.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    });
    locationAlert.show();
}

つまり、これは 2 つの異なるリストを持つ 2 つの異なるアクティビティであり、2 つの異なるリストビューを使用し、それぞれがまったく異なることを行う独自の onListItemClick メソッドを持っています。

于 2012-05-04T04:01:30.420 に答える