setOnItemClickListener 内で、インテントを使用して新しいアクティビティを開始します。この意図のために、私は7つの弦をエキストラとして入れました。(ListView の) アイテムをクリックすると、これらすべてのエクストラが (新しい画面に) 表示されます。しかし、最初の 4 つのエキストラしか表示されません。新しいアクティビティのレイアウト ファイルは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/address_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/city_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="@+id/zip_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="@+id/state_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
</LinearLayout>
<TextView
android:id="@+id/name_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="@+id/number_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="@+id/store_id_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip"/>
</LinearLayout>
次に、リスナーのコードを次に示します。
lv_custom.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Log.v("ITEM",lv_custom.getItemAtPosition(position).toString());
c.moveToPosition(position);
String adr = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_ADDRESS));
String city = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_CITY));
String name = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_NAME));
String store_id = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_STORE_ID));
String phone = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_PHONE));
String zip = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_ZIP));
String state = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_STATE));
Intent intent=new Intent(DisplayActivity.this,DisplayInfoActivity.class);
intent.putExtra("Address: ",adr);
intent.putExtra("City: ", city);
intent.putExtra("Zip: ", " " + zip + ", ");
intent.putExtra("State: ", state);
intent.putExtra("Name: ", name);
intent.putExtra("Store ID: ", "Store ID " + store_id);
intent.putExtra("Phone: ", phone);
startActivity(intent);
}
});
新しいアクティビティ コードは次のとおりです。
public class DisplayInfoActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_entry);
TextView address = (TextView) findViewById(R.id.address_entry);
TextView city = (TextView) findViewById(R.id.city_entry);
TextView zip = (TextView) findViewById(R.id.zip_entry);
TextView state = (TextView) findViewById(R.id.state_entry);
TextView name = (TextView) findViewById(R.id.name_entry);
TextView store_id = (TextView) findViewById(R.id.store_id_entry);
TextView phone = (TextView) findViewById(R.id.number_entry);
Intent intent = getIntent();
address.setText(intent.getStringExtra("Address: "));
city.setText(intent.getStringExtra("City: "));
zip.setText(intent.getStringExtra("Zip: "));
state.setText(intent.getStringExtra("State: "));
name.setText(intent.getStringExtra("Name: "));
store_id.setText(intent.getStringExtra("Store ID: "));
phone.setText(intent.getStringExtra("Phone: "));
}
}
問題は、住所、都市、郵便番号、州しか表示されないことです。名前、店舗ID、電話番号は表示されません。それらはどうなりますか?新しい画面に表示されない/表示されないのはなぜですか? 実際、エクストラを追加する前に、インテント内のすべてのエクストラを確認できました。エクストラの数に問題はありますか?あなたが私に答えを持っているなら、助けてくれてありがとう!