我使用列表視圖來顯示從database..when我添加了消息時 通吃的字符串,並顯示在listview..here消息是我的xml文件和java .. 我需要以'...'的每行以單線形式獲取消息。我研究了這個問題,我發現,類型 機器人:單線=「真」中的TextView,但我不知道他們是什麼意思「在textview'.becauz我使用listview.please幫助。最小化的ListView一行成一行
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/wave" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/SearchMessageExit"
android:focusableInTouchMode="true"
>
</ListView>
</LinearLayout>
message.java
public void detailsOfMessage(){
try{
Database_message info = new Database_message(this);
String data = info.getData();
info.close();
if(data.equals(""))
{
Toast.makeText(getApplicationContext(), "Empty Message", Toast.LENGTH_LONG).show();
}
StringTokenizer token = new StringTokenizer(data,"\t");
int rows = token.countTokens();
classes = new String[rows];
int i=0;
while (token.hasMoreTokens())
{
classes[i]=token.nextToken();
i++;
}
listView = (ListView) findViewById(R.id.list);
listView.setOnItemClickListener(this);
listView.setOnLongClickListener(this);
inAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,0);
listView.setAdapter(inAdapter);
for (int r = 0; r < classes.length; r++) {
inAdapter.add(classes[r]);
}
}catch(Exception e){
Toast.makeText(getApplicationContext(), "Empty Message", Toast.LENGTH_LONG).show();
}
}
謝謝。當我嘗試運行這段代碼時,我得到一個異常'arrayadapter需要資源ID爲textview'。然後我刪除了linearlayout,並創建了只有textview的佈局。現在它完美地工作... –
多數民衆贊成在很大程度上..如果答案已經幫助你,那麼你可以接受它作爲答案,並upvote它,使其他人也可以發現它有用。 –
但是,想到的是我對這個網站新..所以我需要15聲望voteup.sorry。 –