2017-07-11 1 views
-1
klickt

Ich implementiere eine App, wo ich den Text der Schaltfläche ändern möchte, wenn ich auf den Button klicken werde.Der folgende Code habe ich bisher versucht, bitte sagen Sie mir, wo bin Fehler machen.Wie man den Text der Schaltfläche ändert, wenn jemand auf die Schaltfläche in Android

private void shortlist(){ 

     StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String> () { 
      @Override 
      public void onResponse(String response) { 
       Log.e("short response-------",response); 
       if(response.equalsIgnoreCase("success")) { 
        btnSort.setText("shortlisted"); 
        btnSort.setEnabled(false); 
       } 

       Toast.makeText(getContext(), response, Toast.LENGTH_LONG).show(); 
      } 
     }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse(VolleyError error) { 
         Toast.makeText(getContext(), error.toString(), Toast.LENGTH_LONG).show(); 
        } 
       }) { 
      @Override 
      protected Map<String, String> getParams() { 
       Map<String, String> params = new HashMap<String, String>(); 
       params.put(KEY_MATRI_ID_BY,matri_id_by); 
       params.put(KEY_MATRI_ID_TO,matri_id_to); 
       return params; 
      } 
     }; 
     RequestQueue requestQueue = Volley.newRequestQueue(getContext()); 
     requestQueue.add(stringRequest); 
    } 
+0

Es funktioniert nicht, wenn Klick auf den Button. –

+0

Vielleicht liegt das daran, dass Sie onClickListener nicht auf die Schaltfläche gesetzt haben? –

+0

Ja, ich habe onClickListener auf Schaltfläche –

Antwort

0

public class Profile_Match_custom_List erweitert ArrayAdapter {

private static final String url ="http://10.0.2.2/xp/shortlist1.php"; 
private static final String url1 = "http://10.0.2.2/xp/express_intrest.php"; 
private static final String KEY_MATRI_ID_TO="matriID_to"; 
private static final String KEY_MATRI_ID_BY="matriID_by"; 

SessionManager session; 
public String matri_id_to, matri_id_by, str_gender; 

String str; 


private NetworkImageView imageView; 
private ImageLoader imageLoader; 
private final String[] ids; 
private String[] ages; 
private String[] heights; 
public String[] communities; 
public String[] castes; 
public String[] educations; 
public String[] occupations; 
public String[] incomes; 
public String[] pics; 
public String[] locations; 
public String[] shortlist; 
public String[] expressinterest; 
private Activity context; 


public Profile_Match_custom_List(Activity context, String[] ids, String[] ages, 
           String[] heights, String[] communities, String[] castes, 
           String[] educations, String[] occupations, String[]incomes, 
           String[]pics, String[] locations, String[] shortlist, String[] expressinterest) { 
    super(context, R.layout.custom_profile_match,ids); 
    this.ids = ids; 
    this.ages = ages; 
    this.heights = heights; 
    this.communities = communities; 
    this.castes = castes; 
    this.educations = educations; 
    this.occupations = occupations; 
    this.incomes = incomes; 
    this.pics = pics; 
    this.locations = locations; 
    this.shortlist = shortlist; 
    this.expressinterest = expressinterest; 
    this.context = context; 
} 


static class ViewHolder{ 
    public Button btnSort; 
} 

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 

    ViewHolder viewHolder = null; 


    viewHolder = new ViewHolder(); 


    LayoutInflater inflater = context.getLayoutInflater(); 
    final View listViewItem = inflater.inflate(R.layout.custom_profile_match, null, true); 

    // Session class instance 
    session = new SessionManager(getContext()); 
    session.checkLogin(); 
    // get user data from session 
    HashMap<String, String> user = session.getUserDetails(); 

    matri_id_by = user.get(SessionManager.KEY_EMAIL); 
    str_gender = user.get(SessionManager.KEY_GENDER); 

    String url1 = "https://www.maangal.com/thumb/thumb_"; 
    String url = url1 + pics[position]; 

    imageView = (NetworkImageView) listViewItem.findViewById(R.id.offer_image); 
    imageLoader = CustomVolleyRequest.getInstance(this.getContext()).getImageLoader(); 
    if(str_gender.equals("Male")) { 
     imageLoader.get(url, ImageLoader.getImageListener(imageView, R.drawable.image, R.drawable.girl)); 
    } 
    else { 
     imageLoader.get(url, ImageLoader.getImageListener(imageView, R.drawable.image, R.drawable.boy)); 
    } 
    imageView.setImageUrl(url,imageLoader); 
    TextView textViewId = (TextView) listViewItem.findViewById(R.id.textViewId); 
    TextView textViewName = (TextView) listViewItem.findViewById(R.id.textViewName); 

    textViewId.setText(ids[position]); 

    textViewName.setText(ages[position]+" years"+" , "+heights[position]+" cm"+", "+communities[position]+" : "+castes[position]+" , "+educations[position]+" , "+occupations[position]+" , "+incomes[position]+", "+locations[position]); 


    imageView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent i = new Intent(v.getContext(), BlankActivity.class); 
      Toast.makeText(getContext(), ids[position], Toast.LENGTH_LONG).show(); 
      i.putExtra("id", ids[position]); 
      v.getContext().startActivity(i); 
     } 
    }); 

    viewHolder.btnSort =(Button) listViewItem.findViewById(R.id.btnshort); 
    viewHolder.btnSort.setText("abhachfhfhf"); 
    final ViewHolder finalViewHolder = viewHolder; 
    viewHolder.btnSort.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) 
     {matri_id_to=ids[position]; 


      Toast.makeText(getContext(), "Success", Toast.LENGTH_LONG).show(); 
      // shortlist(); 
      //Button b = (Button) v; 
      finalViewHolder.btnSort.setText(shortlist[position]); 
     } 
    }); 

    Button btnChat =(Button) listViewItem.findViewById(R.id.btnchat); 
    btnChat.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      matri_id_to=ids[position]; 
      Toast.makeText(getContext(),"sent express intrest",Toast.LENGTH_LONG).show(); 
      express_Intrest(); 
     } 
    }); 

    Button declineButton = (Button)listViewItem.findViewById(R.id.declineButton); 
    declineButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
     } 
    }); 
    return listViewItem; 
} 

private void shortlist(){ 

    StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String> () { 
     @Override 
     public void onResponse(String response) { 
      Log.e("short response-------",response); 
      if(response.equalsIgnoreCase("success")) { 
       //btnSort.setText("shortlisted"); 
       // btnSort.setEnabled(false); 
      } 

      Toast.makeText(getContext(), ""+matri_id_to, Toast.LENGTH_LONG).show(); 
     } 
    }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        Toast.makeText(getContext(), error.toString(), Toast.LENGTH_LONG).show(); 
       } 
      }) { 
     @Override 
     protected Map<String, String> getParams() { 
      Map<String, String> params = new HashMap<String, String>(); 
      params.put(KEY_MATRI_ID_BY,matri_id_by); 
      params.put(KEY_MATRI_ID_TO,matri_id_to); 
      return params; 
     } 
    }; 
    RequestQueue requestQueue = Volley.newRequestQueue(getContext()); 
    requestQueue.add(stringRequest); 
} 

public void express_Intrest(){ 
    StringRequest stringRequest1 = new StringRequest(Request.Method.POST, url1, new Response.Listener<String>() { 
     @Override 
     public void onResponse(String response) { 

      Log.e("response",response); 
      Toast.makeText(getContext(), response, Toast.LENGTH_LONG).show(); 
     } 
    }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        Toast.makeText(getContext(), error.toString(), Toast.LENGTH_LONG).show(); 
       } 
      }) { 
     @Override 
     protected Map<String, String> getParams() { 
      Map<String, String> params = new HashMap<String, String>(); 

      params.put(KEY_MATRI_ID_BY,matri_id_by); 
      params.put(KEY_MATRI_ID_TO,matri_id_to); 

      return params; 
     } 
    }; 
    RequestQueue requestQueue = Volley.newRequestQueue(getContext()); 
    requestQueue.add(stringRequest1); 
} 

}

+0

Ich habe diesen Code verwendet, wo der Schaltfläche Text beim Klicken geändert wird, aber wenn ich es scrollte der Text im vorherigen Text geändert. Kann mir jemand helfen, was soll ich tun? –

Verwandte Themen