이 목록 뷰가 표시되지 않는 문제는 매우 기묘한 것으로 보입니다. 먼저 활동과 관련된 기능 코드를 게시하겠습니다. ListView mListView;ListView의 getCount()가 올바르게 작동하지만 ListView가 표시되지 않음
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.result);
mListView = (ListView)this.findViewById(R.id.wrdList);
handleIntent(getIntent());
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String word = intent.getStringExtra(SearchManager.QUERY);
//use the query to search your data somehow
//Columns to be selected in database
String sel[] = {"_id", "wort", DictDBHelper.get2LtrLang()};
Cursor SrhRet = mSrhHelper.searchWord(word, sel);
//Columns to be showed in ListView
String col[] = {"wort", DictDBHelper.get2LtrLang()};
showList(SrhRet, col);
SrhRet.close();
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
}
}
/*
* Set the TextView to print how many words are found in database
*/
protected void setCount(int count) {
TextView tv = (TextView)this.findViewById(R.id.wrdCount);
tv.setText(String.valueOf(count));
}
/*
* Set the adapter to show the list
* First parameter specifies the cursor of rows to be shown in ListView
* Second one specifies columns
*/
protected void showList(final Cursor SrhRet, String[] from) {
int[] to = new int[]{R.id.entry, R.id.detail};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.listitem, SrhRet, from, to,
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
mListView.setAdapter(adapter);
setCount(mListView.getCount());
mListView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Build the Intent used to open WordActivity with a specific word Uri
Intent wordIntent = new Intent(getApplicationContext(), WordActivity.class);
Uri data = Uri.withAppendedPath(DictionaryProvider.ENTRY_CONTENT_URI,
String.valueOf(id));
wordIntent.setData(data);
//Required by the update
SrhRet.close();
mSrhHelper.updateHist(id);
startActivity(wordIntent);
}
});
}
이들은 검색 가능한 입력을 처리하는 함수입니다. 관련된 모든 변수를 추적했지만 비정상적인 변수는 거의 찾아 내지 못합니다. 그러나이 함수를 시도 할 때마다 ListView에 포함되어야하는 올바른 숫자가 TextView에 표시됩니다! 이 함수는 이전에 완벽하게 작동했으며이 함수에서 파생 된 다른 활동도 잘 작동하는 이러한 함수를 호출합니다.
내가리스트 뷰의 항목의 내용으로 listitem.xml를 사용
그리고 내 result.xml
<?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" >
<TextView
android:id="@+id/entry"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textSize="17dp" />
<TextView
android:id="@+id/detail"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
. 방향을 다시 확인했습니다.
<?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">
<TextView
android:id="@+id/wrdCount"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<ListView
android:id="@+id/wrdList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
미리 도움을 청하십시오!
일반 정보 match_parent 대신 fill_parent를 사용하십시오. match_parent는 더 이상 요즘 사용되지 않으며 일부 API에서는 u 오류를 제공합니다. 또한 Cursor SrhRet을 전역 변수로 만드십시오. – Shubhayu
@Shubhayu api15에서 개발되었으므로이 문제가 중요하지 않다고 생각합니다. 그리고 나는 그것을 시도했다. 그것도 작동하지 않습니다. – Hypeboyz
오류가 있습니까? 아니면 그냥 빈 목록이 보이십니까? – Shubhayu