사용자 지정 목록 작업을 만들고 있습니다. 확장 된 ListActivity를 갖는 클래스와리스트 활동을위한 ArrayAdapter를 가지는 클래스가 있습니다.EditText 포커스 이벤트에서 ArrayAdapter의 getView() 메서드가 자동으로 호출됩니다.
문제점 1 : 문제는 ListActivity 화면을 여는 중 상단에 검색 상자가 있습니다. ListActivity를 시작하면 현재 포커스가 EditText에 있으므로 키 보드가 자동으로 열립니다. 나는 그것을 멈추고 싶다.
문제 2 : 은 또한 초점 다시 모든 행을 생성 글고 ArrayAdapter와의 의 getView() 메소드 자동 호출지고 간다. 나는 왜 그런 일이 일어나는지 알지 못한다. 나는 notifyDataSetchanged() 메서드를 호출하지 않습니다. 여전히 EditText에 집중하면 getView()가 자동으로 호출됩니다. 그것을 막는 방법?
storelistview.xml :
<?xml version="1.0" encoding="UTF-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/black" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:focusable="true" android:focusableInTouchMode="true">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow android:id="@+id/tableRow2" android:layout_height="wrap_content"
android:gravity="center" android:layout_width="fill_parent"
android:background="#919191">
<EditText android:id="@+id/searchText" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:width="240dp"
android:hint="Search"></EditText>
<ImageView android:layout_width="wrap_content"
android:src="@drawable/search" android:layout_height="wrap_content"
android:id="@+id/searchImage"></ImageView>
</TableRow>
</TableLayout>
<ListView android:id="@+id/android:list" android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:textColor="@color/white" android:textSize="14sp"
android:gravity="top|center" android:text="No store found.." /></LinearLayout>
StoreListView.java :
public class StoreListView extends ListActivity {
private List<Store> stores = new ArrayList<Store>();
private StoreListRowAdapter rowAdapter;
private Runnable fetchStores;
private Handler handler = new Handler();
private ImageView searchImage;
private EditText searchText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.storelistview);
searchText = (EditText) findViewById(R.id.searchText);
searchImage = (ImageView) findViewById(R.id.searchImage);
searchImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}
});
rowAdapter = new StoreListRowAdapter(this, R.layout.storelistview, stores);
setListAdapter(rowAdapter);
fetchStores = new Runnable() {
@Override
public void run() {
Store store = new Store();
StoreListAsynTask s = new StoreListAsynTask();
s.execute(store);
}
};
handler.post(fetchStores);
}
private Runnable resultThread = new Runnable() {
public void run() {
rowAdapter.clear();
for (int i = 0; i < stores.size(); i++) {
Store bean = stores.get(i);
rowAdapter.add(bean);
}
//rowAdapter.notifyDataSetChanged();
}
};
class StoreListAsynTask extends AsyncTask<Store, Void, String> {
private Gson gson = new Gson();
private List<Store> storeList;
private ProgressDialog m_ProgressDialog = null;
@Override
protected String doInBackground(Store... params) {
return respData;
}
@Override
protected void onPostExecute(String result) {
//populate store list
stores = storeList;
runOnUiThread(resultThread);
m_ProgressDialog.dismiss();
}
}
}
StoreListRowAdapter.java :
public class StoreListRowAdapter extends ArrayAdapter<Store> {
List<Store> stores;
public StoreListRowAdapter(Context context, int textViewResourceId, List<Store> stores) {
super(context, textViewResourceId, stores);
this.stores = stores;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.storelist_rowview, null);
}
final Store store = stores.get(position);
if (store != null) {
LinearLayout storeLogoContainer = (LinearLayout) view.findViewById(R.id.storeLogoContainer);
LoaderImageView imageView = new LoaderImageView(getContext(), getContext().getString(R.string.logoUrl), store.getId().getId());
storeLogoContainer.addView(imageView);
TextView storeName = (TextView) view.findViewById(R.id.storeName);
storeName.setText(store.getStoreName());
}
return view;
}
}
'getView()는 많은 시간 호출됩니다. "모든 행을 다시 생성 중"일 수도 있고 아닐 수도 있습니다. getView() 구현이 효율적인지 확인하기 만하면됩니다.'getView()가 호출되는 위치를 알 수있는 방법이 있는지 말해 줄 수 있습니까? 난 그저 일부 요소를 추가하고 notifyDataSetChanged()를 호출 할 때 getView()를 호출하려고한다. – vbjain
실제로 getView()에서 볼 수 있듯이 서버에서 이미지를 가져 오는 하나의 이미지보기가 있습니다. 이제 매번 getView()가 호출 될 때마다 서버에서 이미지를 가져올 것입니다. 이것은 응용 프로그램에서 허용되지 않는 무언가입니다. – vbjain
@vbjain : "getView()가 호출되는 위치를 알 수있는 방법이 있습니까?" -- 아니. "일부 요소를 추가하고 notifyDataSetChanged()를 호출하면 getView()를 호출하려고합니다." - 당신은'getView()'를 결코 호출하지 않고'getView()'가 호출 될 때 당신이 제어하는 것이 아니다. – CommonsWare