|
|

楼主 |
发表于 13-8-2011 08:08 PM
|
显示全部楼层
没人吗。。- public class HelloListViewActivity extends ListActivity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- String[] countries = getResources().getStringArray(R.array.countries_array);
- setListAdapter(new ArrayAdapter<String>(this,R.layout.main, countries));
- ListView lv = getListView();
- lv.setTextFilterEnabled(true);
-
- TextView tv = new TextView(this);
- tv = (TextView) findViewById(R.id.textview);
- if (tv!=null)
-
- {
- tv.setEnabled(false);
-
- Drawable androidmarker = getResources().getDrawable(R.drawable.androidmarker);
- androidmarker.setAlpha(30);
- androidmarker.setBounds(0, 0, androidmarker.getMinimumWidth(), androidmarker.getMinimumHeight());
-
-
- tv.setCompoundDrawables(androidmarker, null, null, null);
- }
-
- lv.setOnItemClickListener(new OnItemClickListener() {
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- // When clicked, show a toast with the TextView text
- Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
- Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
复制代码- <?xml version="1.0" encoding="utf-8"?>
- <TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/textview"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="10dp"
- android:textSize="16sp" >
- </TextView>
复制代码 不知道为什么会碰到NullPointerException,指tv这个TextView
请问有什么解决方法吗 |
|