在android中,当有人点击按钮时,如何更改按钮的文本

在android中,当有人点击按钮时,如何更改按钮的文本,android,Android,我正在实现一个应用程序,当我点击按钮时,我想更改按钮的文本。下面的代码我已经尝试过了,请告诉我哪里出错了 private void shortlist(){ StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String> () { @Override public vo

我正在实现一个应用程序,当我点击按钮时,我想更改按钮的文本。下面的代码我已经尝试过了,请告诉我哪里出错了

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);
    }
private void短名单(){
StringRequest StringRequest=new StringRequest(Request.Method.POST、url、new Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
Log.e(“短响应-------”,响应);
if(response.equalsIgnoreCase(“success”)){
b传感器设置文本(“入围”);
b传感器设置启用(错误);
}
Toast.makeText(getContext(),response,Toast.LENGTH_LONG).show();
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
Toast.makeText(getContext(),error.toString(),Toast.LENGTH_LONG).show();
}
}) {
@凌驾
受保护的映射getParams(){
Map params=新的HashMap();
参数put(关键字矩阵ID,矩阵ID);
参数put(键为MATRI\u ID\u TO,键为MATRI\u ID\u TO);
返回参数;
}
};
RequestQueue RequestQueue=Volley.newRequestQueue(getContext());
添加(stringRequest);
}

公共类配置文件匹配自定义列表扩展了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);
}
private静态最终字符串url=”http://10.0.2.2/xp/shortlist1.php";
私有静态最终字符串url1=”http://10.0.2.2/xp/express_intrest.php";
私有静态最终字符串密钥\u MATRI\u ID\u TO=“matriID\u TO”;
私有静态最终字符串密钥\u MATRI\u ID\u BY=“matriID\u BY”;
会话管理器会话;
公共字符串matri_id_to、matri_id_by、str_gender;
字符串str;
专用网络图像视图;
私有图像加载器;
私有最终字符串[]id;
私人字符串[]年龄;
私人字符串[]高度;
公共社区;
公共种姓;
公共教育;
公共职业;
公共收入;
公共字符串[]图片;
公共字符串[]位置;
公共字符串[]短名单;
公众利益;
私人活动语境;
公共配置文件匹配自定义列表(活动上下文、字符串[]ID、字符串[]年龄、,
字符串[]高度,字符串[]社区,字符串[]种姓,
String[]教育,String[]职业,String[]收入,
字符串[]图片、字符串[]位置、字符串[]短名单、字符串[]expressinterest){
super(上下文、右布局、自定义配置文件匹配、ID);
this.ids=ids;
this.ages=年龄;
这个高度=高度;
这个社区=社区;
这个。种姓=种姓;
教育=教育;
这个职业=职业;
这就是收入=收入;
this.pics=pics;
这个位置=位置;
this.shortlist=短名单;
this.expressinterest=expressinterest;
this.context=上下文;
}
静态类视窗夹{
公共按钮传感器;
}
@凌驾
公共视图getView(最终整数位置、视图转换视图、视图组父视图){
ViewHolder ViewHolder=null;
viewHolder=新的viewHolder();
LayoutInflater充气器=上下文。getLayoutInflater();
最终视图listViewItem=充气机。充气(R.layout.custom\u profile\u match,null,true);
//会话类实例
session=newsessionmanager(getContext());
session.checkLogin();
//从会话获取用户数据
HashMap user=session.getUserDetails();
matri_id_by=user.get(SessionManager.KEY_EMAIL);
str_gender=user.get(SessionManager.KEY_gender);
字符串url1=”https://www.maangal.com/thumb/thumb_";
字符串url=url1+pics[位置];
imageView=(NetworkImageView)listViewItem.findViewById(R.id.offer\u image);
imageLoader=CustomVolleyRequest.getInstance(this.getContext()).getImageLoader();
如果(男女平等(“男性”)){
get(url,imageLoader.getImageListener(imageView,R.drawable.image,R.drawable.girl));
}
否则{
get(url,imageLoader.getImageListener(imageView,R.drawable.image,R.drawable.boy));
}
setImageUrl(url,imageLoader);
TextView textViewId=(TextView)listViewItem.findViewById(R.id.textViewId);
TextView textViewName=(TextView)listViewItem.findViewById(R.id.textViewName);
textViewId.setText(id[position]);
textViewName.setText(年龄[职位]+“年”+“年”+“身高[职位]+“厘米”+”,“+社区[职位]+:“+种姓[职位]+”,“+教育[职位]+”,“+职业[职位]+”,“+收入[职位]+”,“+位置[职位]);
imageView.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Intent i=新的Intent(v.getContext(),BlankActivity.class);
Toast.makeText(getContext(),ids[position],Toast.LENGTH_LONG.show();
i、 putExtra(“id”,id[位置]);
v、 getContext().startActivity(i);
}
});
viewHolder.btSensor=(按钮)listViewItem.findViewById(R.id.btnSort);
viewHolder.btensor.setText(“abhachff”);
最终视图持有者finalViewHolder=视图持有者;
viewHolder.btSensor.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v)
{matri_id_to=ids[position];
Toast.makeText(getContext(),“Success”,Toast.LENGTH_LONG.show();
//入围名单();
//按钮b=(按钮)v;
finalViewHolder.b传感器.setText(短名单[位置]);
}
});
按钮btnChat=(按钮)listViewItem.findViewById(R.id.btnChat);
btnChat.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
matri_id_to=id[positi]