3

これは、ListActivity リストをクリックするとactivity、各アトラクションの詳細を示す新しいリストが開始されます。完全な詳細ページを実装する方法がわかりません。以前の からデータを取得する完全な詳細アクティビティのコードをいくつか見せてもらえますlistか?

パブリック クラス アトラクションリスト アクティビティは、リスト アクティビティを拡張します {



    プライベート スタティック 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;


    @オーバーライド
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        mDbHelper = 新しい MyDB(これ);
        mDbHelper.open();
        c = mDbHelper.getplaces();
setListAdapter(新しい SimpleCursorAdapter(これ、
                  R.layout.list_place、c、
                  からの));

        最終的な ListView lv = getListView();

lv.setOnItemClickListener(新しいOnItemClickListener() {
            public void onItemClick(AdapterView 親、ビュー ビュー、int 位置、長い ID) {

                Intent newActivity = new Intent(view.getContext(), Place.class);     
                startActivity(newActivity);

            }
          });
    }

}

AttractionlistActivity.Class からのアクションを処理するためにこのアクティビティを実装する方法がわかりません

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

    プライベート TextView タイトル。
    プライベート TextView の詳細。
    プライベート TextView の場所。
    プライベート TextView 電話;
    プライベート 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);
    }
}
4

3 に答える 3

3
  1. onListItemClick(...)リスト アクティビティでオーバーライドし、カーソルを使用して選択したアイテムの ID を取得します
  2. 詳細アクティビティを開始して、ID をインテント エクストラに渡します
  3. 詳細アクティビティで、ID を回復し、カーソルを開いて DB からデータを取得します。
  4. ビューにデータを入力します
于 2011-05-31T02:03:01.860 に答える
2

Android Notepad Tutorialには、質問を正しく理解していれば、まさにこれの例が含まれています。

于 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 に答える