在我的應用程序去顯示這樣如何顯示消息使用列表視圖在android的佈局的兩側?
請告訴我一個消息,如何顯示在列表視圖中的消息,以及如何顯示一個列表視圖 一個是左,另一種是正確的
和
請怎麼在消息的底部顯示一個時間看我的代碼
//view display
@Override
public View getView(int position, View convertView, ViewGroup parent) {
AllmessagedispalyContants message = (AllmessagedispalyContants) this.getItem(position);
ViewHolder holder;
if(convertView == null)
{
holder = new ViewHolder();
convertView = LayoutInflater.from(mContext).inflate(R.layout.allmessagesms, null);
holder.message = (TextView) convertView.findViewById(R.id.message_text);
holder.date=(TextView)convertView.findViewById(R.id.date);
convertView.setTag(holder);
}
else
holder = (ViewHolder) convertView.getTag();
holder.message.setText(message.getMessage());
holder.date.setText(message.getDate());
LayoutParams lp = (LayoutParams) holder.message.getLayoutParams();
lp = (LayoutParams)holder.date.getLayoutParams();
//check if it is a status message then remove background, and change text color.
if(message.isStatusMessage())
{
holder.message.setBackgroundDrawable(null);
lp.gravity = Gravity.LEFT;
holder.message.setTextColor(R.color.textFieldColor);
}
else
{
//Check whether message is mine to show green background and align to right
if(message.messageType.equals(bool))
{
holder.message.setBackgroundResource(R.drawable.right);
lp.gravity = Gravity.RIGHT;
}
//If not mine then it is from sender to show orange background and align to left
else
{
holder.message.setBackgroundResource(R.drawable.lift);
lp.gravity = Gravity.LEFT;
}
holder.message.setLayoutParams(lp);
holder.message.setTextSize(14);
Typeface typface=Typeface.createFromAsset(mContext.getAssets(),"fonts/Roboto-Bold.ttf");
holder.message.setTypeface(typface);
//holder.message.setTextColor(R.color.textColor);
}
return convertView;
}
private static class ViewHolder
{
TextView message;
TextView date;
}
你需要有一個自定義的listview。檢查這個http://stackoverflow.com/questions/17370525/listview-adapter-with-arbitrary-number-of-row-types-dont-know-the-number-of-di/17370772#17370772。兩個佈局左圖右一個佈局。 – Raghunandan