我创建了使用json从web获取数据的android应用程序并将数据放入listview然后在用户单击并选择特定数据后,系统将在第二个活动中显示详细信息,显示名称和每个值的一些详细信息textview。
问题是用户从列表视图中选择显示为一个块的数据
任何人都可以帮我解决这个错误吗?
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
try {
String item = (String)l.getItemAtPosition(position);
//PostalCodes.get(position);
/*
String PLACENAME = postalCode.get(PLACE_NAME_TAG).toString();
String LATITUDE = postalCode.get(LATITUDE_TAG).toString();
String LONGITUDE = postalCode.get(LONGITUDE_TAG).toString();
String POSTALCODE = postalCode.get(POSTAL_CODE_TAG).toString();
*/
Log.e("position of the Item in the list", "you select the item number " + PostalCodes.getString(position));
Intent in = new Intent(getBaseContext(), Row_Item.class);
in.putExtra("placename", item);
// in.putExtra("lat", LATITUDE);
// in.putExtra("lng", LONGITUDE);
// in.putExtra("postaCode", POSTALCODE);
startActivity(in);
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.e("Error in the onListItemClick",
"LOOK AT THE onListItemClick method");
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_row__item);
Place_Name = (TextView)findViewById(R.id.textView1);
txtlat = (TextView)findViewById(R.id.textLAT);
txtlng = (TextView)findViewById(R.id.textLNG);
txtPostalCode = (TextView)findViewById(R.id.textPSTC);
Bundle b = getIntent().getExtras();
value1 = b.getString("placename");
// value2 = b.getString("lat");
// value3 = b.getString("lng");
// value4 = b.getString("postaCode");
Place_Name.setText(value1);
// txtlat.setText(value2);
// txtlng.setText(value3);
// txtPostalCode.setText(value4);
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Row_Item" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="28dp"
android:text="LAT" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="24dp"
android:text="LNG" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView3"
android:layout_marginTop="32dp"
android:text="POSTAL CODE" />
<TextView
android:id="@+id/textLAT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_alignParentRight="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textLNG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView3"
android:layout_alignParentRight="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textPSTC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView4"
android:layout_alignParentRight="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
答案 0 :(得分:0)
我会将数据保存在不同的TextView中。这似乎是正确获取数据的最佳方式。