在列表视图中插入呼叫按钮

时间:2018-04-12 11:28:41

标签: java android

我有一个项目,显示使用地方搜索的献血者列表,我想在每个用户的列表视图中插入一个呼叫按钮,我不知道如何添加它,你能帮我解决这个问题吗?屏幕截图1:Image 1屏幕截图2:Image献血者的每个细节,如姓名,血型和电话都存储在服务器的每个字段中。 " bld_phn"是显示电话号码的文本视图的ID。"电话"是数组字符串

public class blood extends Activity {

    AsyncHttpClient client;
    JSONArray jarray;
    JSONObject jobject;
    RequestParams params;
    ListView lv;
    EditText enter;
    Button done;
    Button call;
    ArrayList<String> place;
    ArrayList<String>incharge;
    ArrayList<String>email;
    ArrayList<String>phone;
    ArrayList<String>reg;
    ArrayList<String>Bld;
    String temp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.blood);
        //prof=(EditText)findViewById(R.id.userProfile);
        client = new AsyncHttpClient();
        params = new RequestParams();
        //  submit=(Button)findViewById(R.id.submit);
        lv = (ListView) findViewById(R.id.List_all_blood);
        enter=(EditText)findViewById(R.id.enter_bld);

        done=(Button)findViewById(R.id.enter_blood);
        place = new ArrayList<String>();
        incharge = new ArrayList<String>();
        email = new ArrayList<String>();
        phone = new ArrayList<String>();
        reg = new ArrayList<String>();
        Bld = new ArrayList<String>();
        // final RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl2);

//        findViewById(R.id.rl1).setOnClickListener(new View.OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//                imm.hideSoftInputFromWindow(rl.getWindowToken(), 0);
//
//            }
//        });

        done.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                place.clear();
                incharge.clear();
                email.clear();
                phone.clear();
                reg.clear();

                String pl=enter.getText().toString();
                params.put("place",pl);


                client.get("http://srishti-systems.info/projects/accident/bloodsearch.php?", params, new AsyncHttpResponseHandler() {
                    @Override
                    public void onSuccess(String content) {
                        // TODO Auto-generated method stub
                        super.onSuccess(content);
                        System.out.println(content + "jjjjj");

                        try {
                            jobject = new JSONObject(content);
                            Log.e(content, "hgsfdh");

                            String s = jobject.optString("Result");
                            Log.e(content,"dsfds");

                            if(s.equals("success")){
//                          SharedPreferences pref=getApplicationContext().getSharedPreferences("pref",MODE_PRIVATE);
//                          temp=pref.getString("user","");
                                // String a = jobject.optString("PoliceDetails");
                                jarray =jobject.getJSONArray("BloodDoner");
                                for (int i = 0; i < jarray.length(); i++) {
                                    JSONObject obj = jarray.getJSONObject(i);
                                    String FN = obj.getString("firstname");
                                    place.add("First Name  :" + FN);

                                    String LN = obj.getString("lastname");
                                    incharge.add("Second Name  :" + LN);

                                    String mail = obj.getString("email");
                                    email.add("Email  :" + mail);

                                    String ph = obj.getString("phone");
                                    phone.add("Phone  :" + ph);

                                    String bd = obj.getString("bloodgrp");
                                    Bld.add("BLood Group  :" + bd);


                                }

                            }

                            else
                                Toast.makeText(getApplicationContext(),"No Donors Found",Toast.LENGTH_LONG).show();
                           adapter adpt = new adapter();
                            lv.setAdapter(adpt);


                        } catch (Exception e) {

                        }


                    }
                });
            }
        });

    }

    public void hideKeyboard(View view) {
        InputMethodManager imm =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }


    class adapter extends BaseAdapter {
        LayoutInflater Inflater;
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return place.size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }



        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            Inflater=(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView=Inflater.inflate(R.layout.blood_lst,null);
           Viewholder holder=new adapter.Viewholder();

            holder.pl=(TextView)convertView.findViewById(R.id.bld_name);
            holder.pl.setText(place.get(position));

            holder.in=(TextView)convertView.findViewById(R.id.bld_nm);
            holder.in.setText(incharge.get(position));

            holder.em=(TextView)convertView.findViewById(R.id.bld_em);
            holder.em.setText(email.get(position));

            holder.ph=(TextView)convertView.findViewById(R.id.bld_phn);
            holder.ph.setText(phone.get(position));

            holder.ph=(TextView)convertView.findViewById(R.id.bld_grp);
            holder.ph.setText(Bld.get(position));

            return convertView;
        }
        class Viewholder{
            TextView pl;
            TextView in;
            TextView em;
            TextView ph;




        }
    }

}

页面的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:id="@+id/rl2"
    android:background="#9e9e9e">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:id="@+id/List_all_blood"
        android:layout_below="@+id/enter_bld"
        />

    <EditText
        android:hint="enter place"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/enter_bld"
        android:layout_weight="1"
        android:layout_marginTop="49dp"
        android:textColor="#000000"
        android:textStyle="italic"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/enter_policebutton"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <Button
        android:text="done"
        android:layout_width="wrap_content"
        android:layout_height="25dp"
        android:textColor="#FFFFFF"
        android:background="#3F51B5"
        android:layout_marginRight="34dp"
        android:layout_marginEnd="34dp"
        android:id="@+id/enter_blood"
        style="@style/Widget.AppCompat.Button"
        android:layout_alignBaseline="@+id/enter_bld"
        android:layout_alignBottom="@+id/enter_bld"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/enter_blood"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="11dp"
        android:text="Blood Doners" />

</RelativeLayout>

列表的xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#9e9e9e">

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:layout_marginTop="25dp"
        android:textSize="15dp"
        android:layout_marginLeft="30dp"
        android:id="@+id/bld_name" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="30dp"
        android:textSize="15dp"

        android:textColor="#000000"
        android:id="@+id/bld_nm"
        android:layout_below="@+id/bld_name" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:layout_marginTop="15dp"
        android:textSize="15dp"
        android:layout_marginLeft="30dp"
        android:id="@+id/bld_em" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:textColor="#000000"
        android:layout_marginTop="15dp"
        android:textSize="15dp"
        android:layout_marginLeft="30dp"
        android:id="@+id/bld_phn" />
    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:textColor="#000000"
        android:layout_marginTop="15dp"
        android:textSize="15dp"
        android:layout_marginLeft="30dp"
        android:id="@+id/bld_grp" />
</TableLayout>

1 个答案:

答案 0 :(得分:0)

对于listview中的通话按钮,您可以在列表视图的行文件中添加呼叫按钮图标,如下所示: -

    <Button
        android:id="@+id/buttonCall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Call" />

然后在活动中,您可以在Android中点击呼叫按钮以调用功能来编写下面的代码: -

Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("phone number"));
    startActivity(callIntent);
上面代码中的

电话号码是一个字符串var,您可以在其中添加要呼叫的号码。

我希望它会对你有所帮助。