如何设置视图或活动来处理以前的列表活动?例如“查看完整详细信息页面”

时间:2011-05-31 01:54:16

标签: android view simplecursoradapter settext android-cursoradapter

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

public class AttractionsListActivity extends ListActivity {



    private static MyDB mDbHelper;
    String[] from = new String[] { Constants.TITLE_NAME , Constants.ADDRESS_NAME };
    int[] to = new int[] {R.id.place_title, R.id.place_address};
    private Cursor c;


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


        mDbHelper = new MyDB(this);
        mDbHelper.open();
        c = mDbHelper.getplaces();
setListAdapter(new SimpleCursorAdapter(this, 
                  R.layout.list_place, c, 
                  from, to));

        final ListView lv = getListView();

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);

            }
          });
    }

}

我不知道如何实施此活动来处理来自AttractionslistActivity.Class

的操作

public class Place extends Activity {
    private static final String CLASSTAG = Place.class.getSimpleName();

    private TextView title;
    private TextView detail;
    private TextView location;
    private TextView phone;
    private ImageView placeImage;

    public void 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);
    }
}

3 个答案:

答案 0 :(得分:3)

  1. 在列表活动中覆盖onListItemClick(...),使用Cursor获取所选项目的ID
  2. 启动您的详细信息活动,通过意图附加内容传递ID
  3. 在您的详细信息活动中,恢复ID并打开游标以从数据库中恢复数据。
  4. 使用数据填写您的观点

答案 1 :(得分:2)

如果我正确理解了这个问题,Android Notepad Tutorial就会包含一个这样的例子。

答案 2 :(得分: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.