android在r中定义list,android - Listview错误:“您的内容必须有一个ListView,其id属性为'android.R.id.list'” - 堆栈内存溢出...

我的logcat中出现错误,说“你的内容必须有一个ListView,其id属性是'android.R.id.list'”。 我的代码编译并运行但在我开始listview活动时强制关闭。 我检查了很多类似的问题,这似乎是一个常见的问题,但我仍然无法修复我的代码。

宣言:

private ListView lv;

Context mContext;

List mList;

String[] testcontacts;

MessageView aa = null;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.firstlist);

testcontacts = getResources()

.getStringArray(R.array.testcontacts_array);

aa = new MessageView();

lv = getListView();/*(ListView) lv.findViewById(R.id.list); Had to comment out, it cannot find list*/

lv.setAdapter(aa);

lv.setTextFilterEnabled(true);

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();

}

});

}

class MessageView extends ArrayAdapter {

MessageView() {

super(FirstLoginActivity.this, android.R.layout.activity_list_item,

testcontacts);

// TODO Auto-generated constructor stub

}

public View getView(int position, View convertview, ViewGroup parent) {

Log.d("Ebz", "inside getView method");

ViewHolder holder;

View v = convertview;

if (v == null) {

Log.d("Ebz", "if v == null");

LayoutInflater inflater = getLayoutInflater();

v = inflater.inflate(R.layout.list_items, null);

holder = new ViewHolder();

holder.firstLine = (TextView) v.findViewById(R.id.firstLine);

holder.secondLine = (TextView) v.findViewById(R.id.secondLine);

holder.icon1 = (ImageView) v.findViewById(R.id.icon1);

holder.icon2 = (ImageView) v.findViewById(R.id.icon2);

v.setTag(holder);

} else {

holder = (ViewHolder) v.getTag();

}

holder.firstLine.setText(testcontacts[position]);

holder.secondLine.setText(testcontacts[position]);

holder.icon1.setImageBitmap(null);

holder.icon2.setImageBitmap(null);

// call the images directly?

return v;

}

class ViewHolder {

TextView firstLine;

TextView secondLine;

ImageView icon1;

ImageView icon2;

}

}

}

我的XML

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical" >

android:id="@+id/top_control_bar"

android:layout_width="fill_parent"

android:layout_height="wrap_content" >

android:id="@+id/textView1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginBottom="10dp"

android:layout_weight="1"

android:background="#cc252a"

android:paddingBottom="10dp"

android:paddingLeft="10dp"

android:paddingTop="10dp"

android:text="This will be Changed"

android:textAppearance="?android:attr/textAppearanceLarge" />

android:id="@+id/bottom_control_bar"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true" >

android:id="@+id/list"

android:layout_width="fill_parent"

android:layout_height="0dip"

android:layout_above="@id/bottom_control_bar"

android:layout_below="@id/top_control_bar"

android:choiceMode="multipleChoice" />

我的ListItems:

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical" >

android:id="@+id/top_control_bar"

android:layout_width="fill_parent"

android:layout_height="wrap_content" >

android:id="@+id/textView1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginBottom="10dp"

android:layout_weight="1"

android:background="#cc252a"

android:paddingBottom="10dp"

android:paddingLeft="10dp"

android:paddingTop="10dp"

android:text="This will be Changed"

android:textAppearance="?android:attr/textAppearanceLarge" />

android:id="@+id/bottom_control_bar"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true" >

android:id="@+id/list"

android:layout_width="fill_parent"

android:layout_height="0dip"

android:layout_above="@id/bottom_control_bar"

android:layout_below="@id/top_control_bar"

android:choiceMode="multipleChoice"

android:divider="#cc252a"

android:dividerHeight="14.5dp" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值