自定义listView的Item的样式出现问题 求教

zhoujiaolongde zhoujiaolongde 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我现在自己定义一个ListView Item的样式报错误如下:
07-26 06:18:03.717: ERROR/ArrayAdapter(723): You must supply a resource ID for a TextView
07-26 06:18:03.826: ERROR/AndroidRuntime(723): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
07-26 06:18:03.826: ERROR/AndroidRuntime(723): at
07-26 06:18:03.826: ERROR/AndroidRuntime(723): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
07-26 06:18:03.826: ERROR/AndroidRuntime(723): at android.widget.Array


有没有人以前也遇到过相似的问题 ,求解答。万分感激。
代码如下:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flowListRow"
android:background="@drawable/news_bg"
android:layout_width="fill_parent"
android:layout_height="40dp">
<TextView android:id="@+id/flow_type"
android:text="请假及出差申请"
android:textColor="#696969"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:textSize="6dip"
android:layout_marginTop="1dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="5dp"
android:ellipsize="end"
android:layout_width="match_parent"
android:scrollHorizontally="true"
/>

<TextView android:id="@+id/flow_name"
android:text="年休假申请"
android:textColor="@color/black"
android:layout_marginTop="1dip"
android:layout_below="@id/flow_type"
android:layout_alignParentLeft="true"
android:layout_marginLeft="8dp"
android:textSize="12dip"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TextView>

<TextView android:id="@+id/below_node"
android:text="上一节点"
android:textColor="@color/black"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="6dp"
android:textSize="6dip"
android:layout_marginTop="1dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/flow_autor">

</TextView>
<TextView
android:id="@+id/flow_autor"
android:layout_width="wrap_content"
android:textSize="8dip"
android:text="申请人:*** 2012-07-01"
android:textColor="@color/black"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"></TextView>


</RelativeLayout>






然后自己定义了一个adapter
package com.hundsun.zhou.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hundsun.zhou.R;
import com.hundsun.zhou.vo.FlowVO;

/**
* @author zhoujl
* @since 2012/07/26 10:17:38
*/
public class FlowListAdapter extends BaseAdapter {

private Context context;
private ArrayList<FlowVO> mData ;
// private LayoutInflater mInflater;
// private int textViewResourceId;
/**
* @param context
* @param resource
* @param textViewResourceId
* @param objects
*/
public FlowListAdapter(Context context
) {
this.context = context;
//mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public FlowListAdapter(Context context,ArrayList<FlowVO> list
) {
this.context = context;
this.mData = list;
//mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public void addItem(FlowVO flowVO) {
mData.add(flowVO);
notifyDataSetChanged();
}

public void removeItem(int position) {
mData.remove(position);
notifyDataSetChanged();
}

@Override
public int getCount() {
return mData.size();
}

@Override
public FlowVO getItem(int position) {
return (FlowVO)mData.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
/* ViewHolder holder = null;
FlowVO data = mData.get(position);
holder = new ViewHolder();
//RelativeLayout llContent = (RelativeLayout) convertView.findViewById(R.id.flowListRow);
convertView = mInflater.inflate(textViewResourceId, null);
holder.textView = (TextView)convertView.findViewById(R.id.flow_type);
holder.textView1 = (TextView)convertView.findViewById(R.id.flow_name);
holder.textView2 = (TextView)convertView.findViewById(R.id.below_node);
holder.textView3 = (TextView)convertView.findViewById(R.id.flow_autor);
holder.textView.setText(data.getFlowType());
holder.textView1.setText(data.getFlowName());
holder.textView2.setText(data.getFlowBelowNodeName());
holder.textView3.setText(data.getFlowAutorName());
//llContent.addView(holder.textView);
//llContent.addView(holder.textView1);
//llContent.addView(holder.textView2);
//llContent.addView(holder.textView3);
convertView.setTag(holder);
return convertView;*/
if(mData == null) {
return null;
}
if(convertView == null) {
FlowListItemView flowListItemView= new FlowListItemView(context);
flowListItemView.updateView(mData.get(position));
convertView =flowListItemView;
}else {
((FlowListItemView)convertView).updateView(mData.get(position));
}
return convertView;
}





}


flowListItemView
package com.hundsun.zhou.adapter;

import com.hundsun.zhou.R;
import com.hundsun.zhou.vo.FlowVO;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
* @author zhoujl
* @since 2012/07/26 13:41:17
*/
public class FlowListItemView extends RelativeLayout {

private Context context;
private TextView flowName,flowType,flowAutor,flowBelowNodeName;

public FlowListItemView(Context context) {
super(context);
this.context = context;
init(context);
}

public void init(Context context) {
this.context = context;
View view = LayoutInflater.from(this.context).inflate(R.layout.flow_list_row, null);
flowName = (TextView)view.findViewById(R.id.flow_name);
flowType = (TextView)view.findViewById(R.id.flow_type);
flowAutor = (TextView)view.findViewById(R.id.flow_autor);
flowBelowNodeName = (TextView)view.findViewById(R.id.below_node);
addView(view);
}

public void updateView(FlowVO flowVO) {
flowName.setText(flowVO.getFlowName());
flowType.setText(flowVO.getFlowType());
flowAutor.setText(flowVO.getFlowAutorName());
flowBelowNodeName.setText(flowVO.getFlowBelowNodeName());
}


}


...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
zhoujiaolongde
Android 80,490 成员 91,375 内容