How to set view or Activity for dealing with previous listactivity? for example "see full detail page"
Asked Answered
H

3

6

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);
    }
}
Hence answered 31/5, 2011 at 1:54 Comment(0)
C
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
Cathe answered 31/5, 2011 at 2:3 Comment(3)
Do you have any example code. i'm very new to programing. sorry for my poor.Hence
@April, you should do the android Notepad tutorial it explains this very wellFontanel
@April as @Programmer Bruce suggests, take a look at the notepad tutorialCathe
A
2

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

Assignation answered 31/5, 2011 at 1:59 Comment(1)
I Agree, if the question is to load a detail/edit screen from a list item on a ListActivity then be sure to run through the Android Notepad tutorialFontanel
S
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.
Symphonist answered 13/6, 2021 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.