Java Android:项目列表单击JSON生成的列表视图-无法单击

Java Android:项目列表单击JSON生成的列表视图-无法单击,java,android,Java,Android,我从url获取JSON,以生成联系人姓名和号码的列表视图。我打算让用户只需点击联系人姓名或电话即可直接拨打电话。但我在检测到该项目时遇到问题。我试图在“Onite McClick”上放一个日志,但它似乎没有被调用。你能帮我看看我哪里做错了吗?这是我的密码 package com.example.hk.sample; import java.io.IOException; import java.util.ArrayList

我从url获取JSON,以生成联系人姓名和号码的列表视图。我打算让用户只需点击联系人姓名或电话即可直接拨打电话。但我在检测到该项目时遇到问题。我试图在“Onite McClick”上放一个日志,但它似乎没有被调用。你能帮我看看我哪里做错了吗?这是我的密码

            package com.example.hk.sample;

            import java.io.IOException;
            import java.util.ArrayList;
            import java.util.HashMap;

            import org.apache.http.HttpResponse;
            import org.apache.http.HttpVersion;
            import org.apache.http.client.ClientProtocolException;
            import org.apache.http.client.HttpClient;
            import org.apache.http.client.methods.HttpPost;
            import org.apache.http.impl.client.DefaultHttpClient;
            import org.apache.http.params.BasicHttpParams;
            import org.apache.http.params.CoreProtocolPNames;
            import org.apache.http.params.HttpParams;
            import org.apache.http.util.EntityUtils;
            import org.json.JSONArray;
            import org.json.JSONException;
            import org.json.JSONObject;

            import android.app.Activity;
            import android.app.ProgressDialog;
            import android.content.Intent;
            import android.os.AsyncTask;
            import android.os.Bundle;
            import android.util.Log;
            import android.view.Menu;
            import android.view.View;
            import android.widget.AdapterView;
            import android.widget.Button;
            import android.widget.ListAdapter;
            import android.widget.ListView;
            import android.widget.SimpleAdapter;
            import android.widget.TextView;
            import android.widget.Toast;

            public class AllAccepted extends Activity {

                ListView list;
                TextView phone;
                TextView name;

                ArrayList<HashMap<String, String>> oslist = new ArrayList<HashMap<String, String>>();
                //URL to get JSON Array
                private static String url;
                //JSON Node Names
                private static final String TAG_OS = "myjson";
                private static final String TAG_VER = "phone";
                private static final String TAG_NAME = "name";
                JSONArray android = null;
                //String matchId = Singleton.getInstance().getMatchIdString();
                String matchId = "80";

                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.all_accepted); 

                    list = (ListView) findViewById(R.id.listView1);

                    url = "http://demo.com/list.php?match_id="+ matchId; 

                    Log.e("final view", "final layout array list");
                    oslist = new ArrayList<HashMap<String, String>>(); 

                    new JSONParse().execute();

                    final Button btnHistory = (Button) findViewById(R.id.goHome);
                    btnHistory.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub    
                            Intent myIntent = new Intent(getApplicationContext(), MainActivity.class);
                            startActivity(myIntent);

                        }
                    });   

                }

                protected void onItemClick(ListView l, View v, int position, long id) {
                    // TODO Auto-generated method stub
                    Log.e("item clicks", "selected: " + position);
                }


                private class JSONParse extends AsyncTask<String, String, JSONObject> {
                    private ProgressDialog pDialog;
                   @Override
                   protected void onPreExecute() {
                       super.onPreExecute();
                       phone = (TextView)findViewById(R.id.listPhone);
                       name = (TextView)findViewById(R.id.listName);
                       pDialog = new ProgressDialog(AllAccepted.this);
                       pDialog.setMessage("Getting Data ...");
                       pDialog.setIndeterminate(false);
                       pDialog.setCancelable(true);
                       pDialog.show();
                   }
                   @Override
                   protected JSONObject doInBackground(String... args) {
                       JSONParser jParser = new JSONParser();
                       // Getting JSON from URL
                       JSONObject json = jParser.getJSONFromUrl(url);
                       return json;
                   }

                    @Override
                    protected void onPostExecute(JSONObject json) {
                        pDialog.dismiss();
                        try {
                               // Getting JSON Array from URL
                               android = json.getJSONArray(TAG_OS);
                               for(int i = 0; i < android.length(); i++){
                               JSONObject c = android.getJSONObject(i);
                               // Storing  JSON item in a Variable
                               String ver = c.getString(TAG_VER);
                               String name = c.getString(TAG_NAME);
                               // Adding value HashMap key => value
                               HashMap<String, String> map = new HashMap<String, String>();
                               map.put(TAG_VER, ver);
                               map.put(TAG_NAME, name);
                               oslist.add(map);
                               //list=(ListView)findViewById(R.id.listView1);
                               ListAdapter adapter = new SimpleAdapter(AllAccepted.this, oslist,
                                       R.layout.all_accepted_layout,
                                       new String[] { TAG_VER,TAG_NAME }, new int[] {
                                               R.id.listPhone,R.id.listName});
                               list.setAdapter(adapter);

                               }
                       } catch (JSONException e) {
                           e.printStackTrace();
                       }
                    }
               }

                @Override
                public boolean onCreateOptionsMenu(Menu menu) {
                    // Inflate the menu; this adds items to the action bar if it is present.
                    getMenuInflater().inflate(R.menu.main, menu);
                    return true;
                } 

                @Override
                public void onBackPressed() {
                }

            }
package.com.example.hk.sample;
导入java.io.IOException;
导入java.util.ArrayList;
导入java.util.HashMap;
导入org.apache.http.HttpResponse;
导入org.apache.http.HttpVersion;
导入org.apache.http.client.ClientProtocolException;
导入org.apache.http.client.HttpClient;
导入org.apache.http.client.methods.HttpPost;
导入org.apache.http.impl.client.DefaultHttpClient;
导入org.apache.http.params.BasicHttpParams;
导入org.apache.http.params.CoreProtocolPNames;
导入org.apache.http.params.HttpParams;
导入org.apache.http.util.EntityUtils;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入android.app.Activity;
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.Menu;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.Button;
导入android.widget.ListAdapter;
导入android.widget.ListView;
导入android.widget.simpledapter;
导入android.widget.TextView;
导入android.widget.Toast;
公共类AllAccepted扩展活动{
列表视图列表;
文本视图电话;
文本视图名称;
ArrayList oslist=新的ArrayList();
//获取JSON数组的URL
私有静态字符串url;
//JSON节点名称
私有静态最终字符串标记_OS=“myjson”;
专用静态最终字符串标记\u VER=“phone”;
私有静态最终字符串标记_NAME=“NAME”;
JSONArray-android=null;
//字符串matchId=Singleton.getInstance().getMatchId字符串();
字符串matchId=“80”;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.all_接受);
列表=(ListView)findViewById(R.id.listView1);
url=”http://demo.com/list.php?match_id=“+matchId;
Log.e(“最终视图”、“最终布局阵列列表”);
oslist=newarraylist();
新建JSONParse().execute();
最终按钮btnHistory=(按钮)findViewById(R.id.goHome);
btnHistory.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
Intent myIntent=newintent(getApplicationContext(),MainActivity.class);
星触觉(myIntent);
}
});   
}
受保护的虚线单击(列表视图l、视图v、整型位置、长id){
//TODO自动生成的方法存根
Log.e(“项目点击”,“选中:+位置”);
}
私有类JSONParse扩展了异步任务{
私人对话;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
phone=(TextView)findViewById(R.id.listPhone);
name=(TextView)findViewById(R.id.listName);
pDialog=newprogressdialog(AllAccepted.this);
setMessage(“获取数据…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(真);
pDialog.show();
}
@凌驾
受保护的JSONObject doInBackground(字符串…args){
JSONParser jParser=新的JSONParser();
//从URL获取JSON
JSONObject json=jParser.getJSONFromUrl(url);
返回json;
}
@凌驾
受保护的void onPostExecute(JSONObject json){
pDialog.disclose();
试一试{
//从URL获取JSON数组
android=json.getJSONArray(TAG_OS);
for(int i=0;ivalue
HashMap=newHashMap();
地图放置(标签,版本);
地图放置(标签名称、名称);
添加(地图);
//列表=(ListView)findViewById(R.id.listView1);
ListAdapter=新Simp
                    list = (ListView) findViewById(R.id.listView1);

                    list.setOnItemClickListener(new OnItemClickListener() {
                        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {

                            Log.e("item clicks", "selected: " + position);
                            String item = list.getItemAtPosition(position).toString();

                            String contactNum = ((TextView)view.findViewById(R.id.listPhone)).getText().toString();

                            Log.e("phone number", contactNum);

                            Intent intent = new Intent(Intent.ACTION_CALL);
                            intent.setData(Uri.parse("tel:" + contactNum));
                            startActivity(intent);
                        }
                    });
listView.setOnItemClickListener(ActivityName.this);
public class MainActivity extends Activity {
ListView lView ;
String[] ara={"a","b","c","d","e","f"};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    lView=(ListView)findViewById(R.id.listView1);
    ListAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,ara);
    lView.setAdapter(adapter);
    lView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub

        }});
}
list.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int position,
                    long id) {
                Log.e("item clicks", "selected: " + position);
                String contactNum = ((TextView)view.findViewById(R.id.listPhone)).getText().toString();
                phoneCall(contactNum);
            }
});
public void phoneCall(String number)
{
            String phoneCallUri = "tel:"+number;
            Intent phoneCallIntent =new Intent(Intent.ACTION_CALL);
            phoneCallIntent.setData(Uri.parse(phoneCallUri));
            startActivity(phoneCallIntent);
}