【发布时间】:2014-01-13 12:42:37
【问题描述】:
我想阅读对话并将其放入 ListView。我该怎么做?
我每行有两个 TextView。我想使用 BaseAdapter 来设置它们。
通过使用这个, 内容://mms-sms/conversations/
*更新:*
我试过这样做:
public ArrayList<String> number = new ArrayList<String>();
public ArrayList<String> body = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(new BaseAdapter(){
public int getCount() {
return number.size();
}
public Object getItem(int position) {
return number.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.contact_row, null);
TextView textView = (TextView) view.findViewById(R.id.textView1);
textView.setText(number.get(position));
return view;
}});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void getcon()
{
Uri uriSMSURI = Uri.parse("content://mms-sms/conversations/");
Cursor cursor = getContentResolver().query(uriSMSURI, null, null, null, "date desc");
cursor.moveToFirst();
while (cursor.moveToNext())
{
String address = cursor.getString(cursor.getColumnIndex("address"));
//String body = cursor.getString(cursor.getColumnIndexOrThrow("body"));
//String read = cursor.getString(cursor.getColumnIndexOrThrow("read"));
String contactName = address;
Uri Nameuri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address));
Cursor cs= getContentResolver().query(Nameuri, new String[]{PhoneLookup.DISPLAY_NAME},PhoneLookup.NUMBER+"='"+address+"'",null,null);
if(cs.getCount()>0)
{
cs.moveToFirst();
contactName = cs.getString(cs.getColumnIndex(PhoneLookup.DISPLAY_NAME));
}
number.add(contactName);
}
}
【问题讨论】:
-
显示列表中的任何问题..??
-
显示记录有没有错误.??
-
没有错误。我只是想要一种方法来做到这一点
-
有没有收到短信数据,>?>
-
请检查这个链接你知道如何在android中实现listview..
http://www.vogella.com/tutorials/AndroidListView/article.html