그래서 JSON을 사용하여 외부 데이터베이스에 의해 채워지는 조각 안에 listview가 있습니다.단편에서 SimpleAdapter를 사용하여 JSON 채워진 목록보기에서 버튼에 onclicklstener 설정
listvie의 각 행에는 textview, imagebutton 및 checkbox가 있습니다.
imagebutton 및 체크 박스 기능을 제공하지만 작동하지 않는 이유가 있습니다.
이
은<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_weight="0.22"
android:background="#309BFF"
android:layout_marginLeft="5dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="14dp"
android:layout_weight="0.81"
android:background="#309BFF"
android:textColor="@color/white"
android:textSize="25sp" />
<ImageButton
android:id="@+id/callButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_gravity="center"
android:src="@drawable/phone" />
</LinearLayout>
<CheckBox
android:id="@+id/selectCurrentCompany"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="14dp" />
</LinearLayout>
</RelativeLayout>
이 버튼을 클릭 할 때 난 내 조각
ImageButton callButton;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.taxi_companies_fragment,
container, false);
DownloadTask downloadTask = new DownloadTask();
downloadTask.execute(strUrl);
declarations(rootView, inflater);
return rootView;
}
public void declarations(View view, LayoutInflater mInflater) {
saveButton = (ImageButton) view.findViewById(R.id.saveButton);
infoButton = (ImageButton) view.findViewById(R.id.infoButton);
mListView = (ListView) view.findViewById(R.id.mListView);
saveButton.setOnClickListener(this);
infoButton.setOnClickListener(this);
View mView = mInflater.inflate(R.layout.taxi_companies_list_view, null);
callButton = (ImageButton) mView.findViewById(R.id.callButton);
callButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity().getApplicationContext(), "callButton" , Toast.LENGTH_SHORT).show();
}
});
}
private class ListViewLoaderTask extends
AsyncTask<String, Void, SimpleAdapter> {
JSONObject jObject;
@Override
protected SimpleAdapter doInBackground(String... strJson) {
try {
jObject = new JSONObject(strJson[0]);
JSONParser urlJsonParser = new JSONParser();
urlJsonParser.parse(jObject);
} catch (Exception e) {
Log.d("JSON Exception1", e.toString());
}
JSONParser urlJsonParser = new JSONParser();
List<HashMap<String, Object>> names = null;
try {
names = urlJsonParser.parse(jObject);
} catch (Exception e) {
Log.d("Exception", e.toString());
}
String[] from = {"name"};
int[] to = { R.id.name};
SimpleAdapter adapter = new SimpleAdapter(getActivity().getApplicationContext(), names,
R.layout.taxi_companies_list_view, from, to);
return adapter;
}
@SuppressWarnings("unchecked")
@Override
protected void onPostExecute(SimpleAdapter adapter) {
mListView.setAdapter(adapter);
for (int i = 0; i < adapter.getCount(); i++) {
HashMap<String, Object> hm = (HashMap<String, Object>) adapter.getItem(i);
String name = (String) hm.get("name");
hm.put("name", name);
hm.put("position", i);
}
}
}
에서 그러나 어떤 이유가 무엇 내가하지 조각의 XML에서 listvieww의 XML에있는 것입니다 아무 반응이 없습니다. 나는 심지어 NPE를 얻지도 않는다.
ImageButton 및 CheckBox 클릭 수신기를 처리하기위한 맞춤형 어댑터를 만들었다 고 생각합니다. –
@HareshChhelana는 뷰를 수행하지 않습니다. mView = mInflater.inflate (R.layout.taxi_companies_list_view, null); 충분히? – user123859
확인 : http://stackoverflow.com/questions/25375831/customarrayadapter-implementationunable-to-get-the-resource-id/25376257#25376257 사용자 정의 어댑터를 만드는 방법에 대해 알아 보겠습니다. –