사용자가 목록보기에서 메모 목록 (그냥 설명)을 볼 수있는 간단한 응용 프로그램에서 작업 중이며 일부 메모를 클릭하면 전체 메모가 새로운 활동에 열립니다 편집해라. 문제는 내가 각 목록 항목에 삭제 버튼을 추가하기로 결정했을 때 발생했다. 이 후 행은 클릭 할 수 없게되었지만 버튼은 클릭 할 수 있습니다. 몇 가지 유사한 주제를 읽었지 만 그 중 일부는 나를 도왔습니다. 내 질문에 어떻게 버튼과 listview "행"을 클릭 할 수 있도록 만드는 것입니다? 효율성에 대해서도 확신하지 못합니다.이 방법을 사용하는 것이 좋지 않다고 생각되면 나에게 더 나은 해결책을 알려주고 그렇지 않으면이 문제에 충실 할 것입니다.ListView는 TextView와 Button으로 구성됩니다.
user_notes.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
list_note.xml :
<TextView
android:id="@+id/list_note_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:paddingLeft="6dip"
android:paddingTop="6dip"
android:textSize="17dip"
android:textStyle="bold" />
<ImageButton
android:id="@+id/ibtn_delete_note"
android:onClick="test"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_weight="0.2"
android:focusable="false"
android:scaleType="fitXY"
android:src="@drawable/delete_note_icon" />
public class UserNotes extends ListActivity{
private ProgressDialog progressDialog;
private ImageButton ibtn_delete_note;
private UserData userData;
private DBFacade dbFacade;
private JSONArray jsonArray;
private ArrayList<HashMap<String, String>> userNotes;
private static final String URL_LOAD_NOTES = "";
private static final String URL_UPDATE_NOTE = "";
private static final String TAG = "UserNotes";
//Drawer attributes
String[] drawer_menu_titles;
private ListView drawer_list;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.user_notes);
drawer_menu_titles = getResources().getStringArray(R.array.drawer_menu_array);
drawer_list = (ListView)findViewById(R.id.left_drawer);
drawer_list.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, drawer_menu_titles));
drawer_list.setOnItemClickListener(new DrawerItemClickListener());
userData = UserData.getInstance();
dbFacade = DBFacade.getInstance();
userNotes = new ArrayList<HashMap<String,String>>();
new loadUserNotes().execute();
ListView listView = getListView();
listView.setItemsCanFocus(true);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//int noteId = Integer.valueOf(((TextView) view.findViewById(R.id.list_note_id)).getText().toString());
Intent i = new Intent(UserNotes.this, DisplayNote.class);
i.putExtra("index", position);
Log.d(TAG, "Index: " + String.valueOf(position));
startActivityForResult(i, 100);
}
});
}
public void test(View v){
Log.d(TAG, "Clicked");
}
class loadUserNotes extends AsyncTask<String, String, String>{
private JSONObject jsonObject;
@Override
protected void onPreExecute(){
super.onPreExecute();
progressDialog = new ProgressDialog(UserNotes.this);
progressDialog.setMessage("Loading notes...");
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(true);
progressDialog.show();
}
@Override
protected String doInBackground(String... arg0) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("logged_in_user_id", String.valueOf(userData.getUserId())));
jsonObject = dbFacade.makeHttpRequest(URL_LOAD_NOTES, "GET", params);
Log.d(TAG, jsonObject.toString());
return null;
}
protected void onPostExecute(String file_url){
progressDialog.dismiss();
try{
if(jsonObject.getInt("success") == 1){
jsonArray = jsonObject.getJSONArray("notes");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject o = jsonArray.getJSONObject(i);
Note tempNote = new Note(o.getInt("note_id"), o.getString("description"), o.getString("data"));
userData.addNote(tempNote);
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("id", o.getString("note_id"));
hashMap.put("description", o.getString("description"));
userNotes.add(hashMap);
//Log.d(TAG, userNotes.get(0).toString());
}
}
Log.d(TAG, "Test: " + userNotes.get(0).toString());
Toast.makeText(UserNotes.this, jsonObject.getString("message"), Toast.LENGTH_LONG).show();
}
catch (JSONException e){
e.printStackTrace();
}
runOnUiThread(new Runnable(){
@Override
public void run() {
UserNotesAdapter listAdapter = new UserNotesAdapter(UserNotes.this,
userNotes,
R.layout.list_note,
new String[] {"description"},
new int[] {R.id.list_note_description});
/*
ListAdapter listAdapter = new SimpleAdapter(UserNotes.this,
userNotes,
R.layout.list_note,
new String[] {"description"},
new int[] {R.id.list_note_description});
*/
setListAdapter(listAdapter);
}
});
}
}
public class UserNotesAdapter extends SimpleAdapter{
public UserNotesAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
view.setClickable(true);
view.setFocusable(true);
view.setBackgroundResource(android.R.drawable.menuitem_background);
return view;
}
}
미리 감사드립니다.