경고 대화 상자에서 목록보기를 사용하고 있지만 대화 상자가 표시되면 아무것도 표시하지 않습니다. 개체를 채우고 경고 대화 상자 앞에 배열 목록에 추가하므로 개체가 비어 있지 않습니다. 내 xml 및 클래스에 대한 코드는 다음과 같습니다.
어댑터를 설정하는 위치 :
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Select a match");
//insert array to constructor
LayoutInflater inflater = getLayoutInflater(savedInstanceState);
View dialogLayout = inflater.inflate(R.layout.dialoglist, null);
matchAdapter testAdapter = new matchAdapter(getContext(), userInfos);
ListView listView = (ListView) dialogLayout.findViewById(R.id.dialogListView);
listView.setAdapter(testAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//do something
}
});
builder.setView(dialogLayout);
AlertDialog alert = builder.create();
alert.show();
맞춤 어댑터 :
class matchAdapter extends ArrayAdapter<userInfo> {
public matchAdapter(Context context, ArrayList<userInfo> test) {
super(context, R.layout.match_result, test);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View customRow = inflater.inflate(R.layout.match_result, parent, false);
userInfo singleItemTest = getItem(position);
/*
TODO: get references to layout elements
*/
TextView username = (TextView) customRow.findViewById(R.id.matchUsername);
TextView sex = (TextView) customRow.findViewById(R.id.matchSex);
TextView age = (TextView) customRow.findViewById(R.id.matchAge);
Button sendRequest = (Button) customRow.findViewById(R.id.matchSendRequest);
username.setText(singleItemTest.getUserName());
return customRow;
}}
row.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/match_result"
android:orientation="horizontal"
android:padding="16dp"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="left">
<TextView
android:id="@+id/matchUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:layout_marginRight="10dp"/>
<TextView
android:id="@+id/matchSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sex"
android:layout_marginRight="10dp"/>
<TextView
android:id="@+id/matchAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"
android:layout_marginRight="10dp"/>
<Button
android:id="@+id/matchSendRequest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Request"
android:minHeight="5dp"
android:minWidth="0dp"
android:layout_marginLeft="80dp"/>
dialoglist.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialogListView"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
</ListView>
마이크. M은 그의 의견이 맞았습니다. arraylist는 실제로 비어 있습니다. 그러나 나는 그것을 지금 고쳤다. for 루프에 대한 멍청한 감독.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다