3

这是我ListActivity 点击列表后,它将开始一个新的activity,显示每个景点的完整细节。我不知道如何实现完整的详细信息页面。你们能告诉我一些从以前检索数据的完整详细活动代码list吗?

公共类 AttractionsListActivity 扩展 ListActivity {



    私有静态 MyDB mDbHelper;
    String[] from = new String[] { Constants.TITLE_NAME , Constants.ADDRESS_NAME };
    int[] to = new int[] {R.id.place_title, R.id.place_address};
    私人光标 c;


    @覆盖
    公共无效 onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        mDbHelper = new MyDB(this);
        mDbHelper.open();
        c = mDbHelper.getplaces();
setListAdapter(新的 SimpleCursorAdapter(这个,
                  R.layout.list_place, c,
                  从到));

        最终列表视图 lv = getListView();

lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView parent, View view,int position, long id) {

                意图 newActivity = new Intent(view.getContext(), Place.class);     
                开始活动(新活动);

            }
          });
    }

}

我不知道如何实现这个活动来处理来自 AttractionslistActivity.Class 的动作

公共类地方扩展活动{
    私有静态最终字符串 CLASSTAG = Place.class.getSimpleName();

    私有 TextView 标题;
    私有 TextView 详细信息;
    私有 TextView 位置;
    私人 TextView 电话;
    私有 ImageView placeImage;

    公共无效 onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.v(Constants.TAG, " " + Place.CLASSTAG + " onCreate");

        this.setContentView(R.layout.detail_place);


        this.title = (TextView) findViewById(R.id.name_detail);
        //title.setText(cursor.getString(Constants.TITLE_NAME));
        this.detail = (TextView) findViewById(R.id.place_detail);
        this.location = (TextView) findViewById(R.id.location_detail);
        this.phone = (TextView) findViewById(R.id.phone_detail);
        this.placeImage = (ImageView) findViewById(R.id.place_image);
    }
}
4

3 回答 3

3
  1. 在您的列表活动中覆盖onListItemClick(...),使用光标获取所选项目的 id
  2. 开始您的 Detail Activity,通过 Intent Extras 传递 id
  3. 在您的详细活动中,恢复 id 并打开游标以从数据库中取回数据。
  4. 用数据填充视图
于 2011-05-31T02:03:01.860 回答
2

如果我正确理解了这个问题,Android 记事本教程就包含了一个这样的例子

于 2011-05-31T01:59:30.970 回答
0
First of all sorry for the late answer,
in your adapter class you can use item click listener achieve this easily, please do the following steps for achieving this.


    lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(
                      AdapterView parent, View view,int position, long id) {
    
                    Intent newActivity = new Intent(
                                         view.getContext(), Place.class);     
                    startActivity(newActivity);
    
              }
     });

for passing list item details into next screen you can use intent extras.before calling start activity u need pass the extras like below.

newActivity.putExtra("name", c.place);
newActivity.putExtra("description", c.placeDscription);
newActivity.putExtra("distance", c.distance);


after u need to call --->  startActivity(newActivity);

if you want pass string, Integer, float, boolean etc...types of data you can like above code.
于 2021-06-13T10:29:59.930 回答