我有一个列表视图,其中使用了两种不同的布局(mycontentmtall 或 mycontenmotall)。我想在单击时更改这两个布局(再次单击一行中的一个对象以从我创建的两个新布局中选择一个(mycontentmtallexapand 或 mycontentmoallexpand))。
我面临的问题是,当我单击列表视图中的项目时,我看不到布局更改。
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
final ViewHolder holder;
// int type = getItemViewType(position);
final Message message = getItem(position);
if (convertView == null) {
holder = new ViewHolder();
// if (type == TYPE_MT) {
if (!message.getIsMO()) {
convertView = mInflater.inflate(R.layout.mycontentmtall,
null);
holder.body = (TextView) convertView
.findViewById(R.id.bodyMT);
holder.date = (TextView) convertView
.findViewById(R.id.dateMT);
holder.from = (TextView) convertView
.findViewById(R.id.fromMT);
holder.status = (TextView) convertView
.findViewById(R.id.statusMT);
} else {
convertView = mInflater.inflate(R.layout.mycontentmoall,
null);
holder.body = (TextView) convertView
.findViewById(R.id.bodyMO);
holder.date = (TextView) convertView
.findViewById(R.id.dateMO);
holder.from = (TextView) convertView
.findViewById(R.id.fromMO);
holder.status = (TextView) convertView
.findViewById(R.id.statusMO);
}
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
// Boolean flag = false;
// final String body = message.getBody();
convertView.setOnClickListener(new OnClickListener() {
private int pos = position;
@Override
public void onClick(View v) {
Toast.makeText(context, "Click-" + pos, Toast.LENGTH_SHORT)
.show();
View newConvertView = null;
if (!message.getIsMO()){
newConvertView = mInflater.inflate(R.layout.mycontentmtallexapand,
null);
holder.body = (TextView) newConvertView
.findViewById(R.id.bodyMTExpand);
holder.date = (TextView) newConvertView
.findViewById(R.id.dateMTExpand);
holder.from = (TextView) newConvertView
.findViewById(R.id.fromMTExpand);
holder.status = (TextView) newConvertView
.findViewById(R.id.statusMTExpand);
}
else
{
newConvertView = mInflater.inflate(R.layout.mycontentmoallexpand,
null);
holder.body = (TextVi`enter code here`ew) newConvertView
.findViewById(R.id.bodymoExpand);
holder.date = (TextView) newConvertView
.findViewById(R.id.datemoExpand);
holder.from = (TextView) newConvertView
.findViewById(R.id.frommoExpand);
holder.status = (TextView) newConvertView
.findViewById(R.id.statusmoExpand);
}
// newConvertView
// .setLayoutParams(new LayoutParams(
// LinearLayout.LayoutParams.MATCH_PARENT,
// LinearLayout.LayoutParams.WRAP_CONTENT));
holder.body.setText(message.getBody());
holder.date.setText(message.getDate());
holder.from.setText(message.getPhoneNumber());
holder.status.setText(String.valueOf(message.getStatus()));
// flag = true;
}
});
// s=body.substring(0, 20);
holder.body.setText(message.getBody());
holder.date.setText(message.getDate());
holder.from.setText(message.getPhoneNumber());
holder.status.setText(String.valueOf(message.getStatus()));
return convertView;
}