这是我的代码,我在列表视图中看不到 textview 的值。
我的吐司不工作
我是Android新手,为什么看不到:
我无法获得的价值
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adpt = new SimpleAdapter(new ArrayList<Contact>(), this);
ListView lView = (ListView) findViewById(R.id.listview_search);
lView.setAdapter(adpt);
lView.setTextFilterEnabled(true);
String[] values = new String[] {
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z"
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
// Assign adapter to ListView
lView.setAdapter(adapter);
// React to user clicks on item
lView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parentAdapter, View view, int position,
long id) {
TextView firstletter = (TextView) view.findViewById(R.id.firstletter);
Toast.makeText(MainActivity.this, firstletter.getText(),
Toast.LENGTH_SHORT).show();
//Intent i = new Intent(getApplicationContext(), ContactsActivity.class);
//i.putExtra("firstletter", name.getText() );
//i.putExtra("email", email.getText());
//startActivityForResult(i, 100);
}
});
}
这是我在 activity_main 布局中的列表视图中的列表项:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff9ac2ff"
android:padding="8dp">
<LinearLayout android:id="@+id/item_layout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dip">
<TextView
android:id="@+id/firstletter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF7F3300"
android:textSize="20dip"
android:textStyle="italic"
/>
</LinearLayout>
</RelativeLayout >