5

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

3 Answers 3

3
  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
3
  • Do you have any example code. i'm very new to programing. sorry for my poor. May 31, 2011 at 2:10
  • @April, you should do the android Notepad tutorial it explains this very well
    – wired00
    May 31, 2011 at 2:22
  • @April as @Programmer Bruce suggests, take a look at the notepad tutorial
    – aromero
    May 31, 2011 at 2:23
2

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

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 tutorial
    – wired00
    May 31, 2011 at 2:21
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.