2014-11-14 1 views
0

내 show category dataloaded 메소드에서 내 setonitemclick 리스너를 선언했습니다. 항목이 목록은 내가 클릭 true로 설정 한내 listitem이 클릭되지 않습니다.

목록보기에서
 #Activity class# 

     private ArrayList <CategoryModel>categoryList; 

      //private static final String[]paths = {"All", "Favourites"}; 



      @Override 
      protected void onCreate(Bundle savedInstanceState) { 

       super.onCreate(savedInstanceState); 

       setContentView(com.bioscope.R.layout.categorylist); 
       save=(Button)findViewById(R.id.save); 


       RecieveCategoriesTask task = new RecieveCategoriesTask(this,"all"); 
       task.execute(); 


       save.setVisibility(View.VISIBLE); 

      } 

      public void showcateogryDataLoaded(ArrayList<CategoryModel> categoryList) { 

        this.categoryList = categoryList; 



        for(CategoryModel c:categoryList) 
        { 
         Log.v("title", c.getTitle()); 
        } 

        CategorysListAdapter adapter=new CategorysListAdapter(this, categoryList); 

        list=(ListView) findViewById(com.bioscope.R.id.listView1); 
        list.setAdapter(adapter); 

        >>list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

         @Override 
         public void onItemClick(AdapterView<?> parent, View view, 
           int position, long id) { 
          // TODO Auto-generated method stub 
          Toast.makeText(CategorySelectonActivity.this, "You Clicked an item ",      Toast.LENGTH_SHORT).show(); 
          System.out.print("done"); 
           //showEventInformaion(position); 



          CheckBox cb = (CheckBox) findViewById(R.id.select_checkbox); 
            if(cb.isChecked()) 
            cb.setChecked(false); 
            else 
            cb.setChecked(true); 
         } 
        }); 


      } 

서버 데이터에 의해 채워집니다 dataloaded 방법은 내 receivertask 클래스에서 호출되는 list.This에 클릭하면 해고되지 않는 토스트있다

#categorylist xml# 

<?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:layout_margin="0dp" 
    android:orientation="vertical" 
    > 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="0dp" 
     android:orientation="vertical" 
     android:padding="0dp" > 
     <TableLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal">  



      </TableRow> 
    </TableLayout> 

     <View 
     android:layout_width="fill_parent" 
     android:layout_height="3dp" 
     android:background="#C0C0C0"/> 

     <ListView 
      android:id="@+id/listView1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:clickable="true" > 
     </ListView> 




    </LinearLayout> 


    <RelativeLayout android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:gravity="bottom" 
     > 

     <Button android:layout_width="fill_parent" 
      android:id="@+id/save" 
      android:visibility="invisible" 
      android:layout_height="wrap_content" 
      android:text="SAVE" 
      android:background="#0099cc" 
      /> 

    </RelativeLayout> 



</RelativeLayout> 

categoryListItem

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="100dp" 
    > 

    <ImageView 
     android:id="@+id/category_icon" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/category_title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@+id/category_icon" 
     android:textSize="28sp" 
     android:textColor="#ffcccccc" 
     android:text="Category Title" /> 

    <TextView 
     android:id="@+id/category_description" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/category_icon" 
     android:layout_below="@+id/category_title" 
     android:textSize="14sp" 
     android:textColor="#ffcccccc" 
     android:text="Cateogry Description" /> 



    <CheckBox 
     android:id="@+id/select_checkbox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/category_title" 
     android:layout_alignBottom="@+id/category_title" 
     android:layout_alignParentRight="true" 
     android:background="#ffcccccc" 
     android:text="" 
     android:focusable="false" 
     android:focusableInTouchMode="false" /> 

</RelativeLayout> 

Receivertask

ProgressDialog dialog; 
String responseString; 

CategorySelectonActivity appContext; 
CreateEventActivity createeventActivity_appContext; 

String url; 
String pageUrl = "get-event-category"; 
private String userIdParameter="user_id="; 

// String name,email,pass,phone; 

public RecieveCategoriesTask(CategorySelectonActivity c, String critiria) { 
    appContext = c; 
    // url = Utility.baseUrl + pageUrl + critiria; 
    // url = Utility.baseUrl + pageUrl; 
    url = "http://bioscopebd.com/mobileappand/getusercategory?"+userIdParameter+"259214143443955553"; 
    Log.i("url", url); 
} 

public RecieveCategoriesTask(CreateEventActivity createEventActivity, 
     String critiria) { 
    createeventActivity_appContext = createEventActivity; 
    // url = Utility.baseUrl + pageUrl + critiria; 
    // url = Utility.baseUrl + pageUrl; 
    url = "http://bioscopebd.com/mobileappand/getusercategory?"+userIdParameter+"259214143443955553"; 
} 

protected void onPreExecute() { 

    dialog = new ProgressDialog(appContext==null?createeventActivity_appContext:appContext); 
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
    dialog.setMessage("Loading Categories..."); 
    dialog.show(); 
    super.onPreExecute(); 

} 

String filterResponseString(String r) { 
    return r.replace("\r\n", ""); 
} 

@Override 
protected String doInBackground(String... uri) { 

    HttpClient httpclient = new DefaultHttpClient(); 
    HttpResponse response; 

    try { 

     response = httpclient.execute(new HttpGet(url)); 
     StatusLine statusLine = response.getStatusLine(); 

     if (statusLine.getStatusCode() == HttpStatus.SC_OK) { 

      ByteArrayOutputStream out = new ByteArrayOutputStream(); 
      response.getEntity().writeTo(out); 
      out.close(); 
      responseString = out.toString(); 
      responseString = filterResponseString(responseString); 

     } else { 
      // Closes the connection. 
      response.getEntity().getContent().close(); 

      Utility.showMessage(appContext, "Cannot Connect To Internet"); 
     } 
    } catch (Exception e) { 
     // TODO Handle problems.. 
    } 
    return responseString; 
} 

@Override 
protected void onPostExecute(String result) { 
    dialog.dismiss(); 

    if (responseString != null) { 
     ArrayList<CategoryModel> categoryList = new ArrayList<CategoryModel>(); 
     ; 
     JSONArray jsonArr; 

     try { 

      Log.v("json", responseString); 

      jsonArr = new JSONArray(responseString); 
      // jsonArr = events.getJSONArray("events"); 

      for (int i = 0; i < jsonArr.length(); i++) { 
       JSONObject jsonObj = jsonArr.getJSONObject(i); 

       CategoryModel category = new CategoryModel(); 

       category.setId(jsonObj.getString("event_cat_id")); 
       category.setTitle(jsonObj.getString("event_cat_title")); 
       category.setDescription(jsonObj.getString("event_cat_desc")); 
       category.setStatus(jsonObj.getBoolean("status")); 

       // event.setLogo(jsonObj.getString("logo").getBytes(Charset.forName("UTF-8"))); 

       /* 
       * event.setStartDate(jsonObj.getString("startDate")); 
       * event.setEndDate(jsonObj.getString("endDate")); 
       * 
       * event.setStartTime(jsonObj.getString("startTime")); 
       * event.setEndTime(jsonObj.getString("endTime")); 
       * event.setCountry(jsonObj.getString("country")); 
       * event.setCity(jsonObj.getString("city")); 
       * event.setAddress(jsonObj.getString("address")); 
       * event.setLogo(jsonObj.getString("logo")); 
       * event.setBanner(jsonObj.getString("banner")); 
       * event.setPhone(jsonObj.getString("phone")); 
       * event.setEmail(jsonObj.getString("email")); 
       * 
       * event.setWeblink(jsonObj.getString("weblink")); 
       * event.setPublishDate(jsonObj.getString("publishDate")); 
       * event.setCategoryId(jsonObj.getString("categoryId")); 
       */ 
       categoryList.add(category); 


      } 

     } catch (JSONException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     if (appContext != null) 
     { 
      appContext.showcateogryDataLoaded(categoryList); 

// CategorySelectonActivity c = new CategorySelectonActivity(); // c.visibleSaveButton();

 } 
     // appContext.showCategoryListDataLoaded(responseString); 
     if(createeventActivity_appContext!=null){ 

      createeventActivity_appContext.showcateogryDataLoaded(categoryList); 
     } 

    } 

    super.onPostExecute(result); 
    // Do anything with response.. 
} 

무엇이 부족합니까 ??

+0

'Receivertask' 클래스를 보여줍니다. – Piyush

+0

listitem xml을 넣을 수 있습니까? –

+0

완료 확인. @ Moradiya Akash – Fay007

답변

2

오류가 발생 했습니까? 내가 당신이 당신의 Activitiy's 레이아웃의 모든 CheckBox을 참조 해달라고 때문에

CheckBox cb = (CheckBox) view.findViewById(R.id.select_checkbox); 

, 그래서 CheckBox은 목록 항목에 있어야합니다 :

CheckBox cb = (CheckBox) findViewById(R.id.select_checkbox); 

변경 그것에 :

이 코드를 참조하십시오 . findViewById

UPDATE

시도를 사용하는 경우 따라서, 당신은 당신의 CheckBox 항목에 android:focusable="false"android:focusableInTouchMode="false"을 추가 onItemClick의 PARAM에서 view를 사용해야합니다.

+0

예 확인란이 목록에 있으며 강제 닫기가 없습니다. 문제는 항목이 클릭되지는 않지만 확인란은 클릭 가능하므로 행을 클릭하려는 것입니다. – Fay007

+0

@FaymeShahriar 네, 사실, 문제는'onListItem'이 전혀 해고되지 않았기 때문입니다. BTW, 아직도 내 대답을 구현할 필요가, 그것을 수정하지 않으면 또 다른 오류를 줄 것이다 :) –

+0

@ FaymeShahriar 내 업데이트 된 답변을 참조하십시오 –

관련 문제