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

发布于 2024-11-11 22:55:39 字数 2089 浏览 6 评论 0原文

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

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

This is my ListActivity after clicking on the list it will start a new activity which shows Full detail of each attraction place. I have no idea how to implement Full detail page. Can you guys show me some code of full detail activity which retrieve data from the previous 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);

            }
          });
    }

}

I have no idea how to implement this activity to deal with the action from 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);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

稍尽春風 2024-11-18 22:55:39
  1. 覆盖列表活动中的 onListItemClick(...),使用光标获取所选项目的 id
  2. 启动详细活动,通过 Intent extras 传递 id
  3. 在详细活动中,恢复 id 并打开用于从数据库取回数据的游标。
  4. 用数据填充您的视图
  1. Override onListItemClick(...) in your List Activity, using the Cursor get the id of the selected item
  2. Start your Detail Activity passing the id through the intent extras
  3. In your Detail Activity, recover the id and open a cursor to get your data back from the DB.
  4. Fill your view with the data
你如我软肋 2024-11-18 22:55:39

Android 记事本教程 包含一个具体的示例,如果我理解的话正确提问。

The Android Notepad Tutorial includes an example of exactly this, if I understand the question correctly.

随心而道 2024-11-18 22:55:39
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.
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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文