0

オブジェクトのリスト ビューを開き、リストの行をクリックすると、その行のニュースの詳細を表示する別のアクティビティが開きます。これまでのところ、リスト内の行がクリックされたときに行の名前を表示する新しいアクティビティを開くことができました。しかし、行ごとにアクティビティを作成して、住所、連絡先情報、各行の営業時間などのさまざまな情報を表示する方法がわかりません。

これは、リストビューを表示する最初のアクティビティです

 // storing string resources into Array
 String []Buildings_halls = getResources().getStringArray(R.array.halls);

    // Binding resources Array to ListAdapter
    this.setListAdapter(new ArrayAdapter<String>(this, R.layout.hallstudent, R.id.listhall, Buildings_halls));

 }

 protected void onListItemClick(ListView lv, View v, int position, long id){
     super.onListItemClick(lv, v, position, id);     

Intent intent = new Intent();
intent.setClass(StudentHall.this, StudentHallSelect.class);

intent.putExtra("position", position);

// Or / And
intent.putExtra("id", String.valueOf(id));
intent.putExtra("description", getResources().getStringArray(R.array.hallsdescription));
startActivity(intent);

        }               

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}
}
this is my second code package 





 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.selecthall);
        // TODO Auto-generated method stub


        Intent intent = getIntent(); 
        int position = intent.getIntExtra("position", 0);
        String halldetails=intent.getStringExtra("description");

        TextView TextView1 = (TextView) findViewById(R.id.select_details);
        TextView1.setText(String.valueOf(halldetails));
        // Here we turn your string.xml in an array
        String[] myKeys = getResources().getStringArray(R.array.halls);

        TextView myTextView = (TextView) findViewById(R.id.selecthalllist);
        myTextView.setText(myKeys[position]);


    }
}



 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/select_details"
        android:padding="10dp"
        android:text="@string/news_description"
        android:textAppearance="?android:attr/textAppearanceMedium" />



</LinearLayout>

新しいアクティビティでリストの名前と Null を取得していますが、array.xml ファイルに保存した詳細は取得していません。ありがとう

4

2 に答える 2

0

選択したオブジェクトをリストから詳細画面に渡す場合はこちら: 特定のリストビュー項目の詳細データを表示する方法

または、データが SQLite DB にある場合は、次のようにします。

  1. CursorAdapter を使用する
  2. 選択したアイテムの id パラメータを渡します
  3. 詳細画面で、ID パラメータを使用して、選択したオブジェクトを照会します。
于 2015-02-04T16:32:02.613 に答える