안녕하세요 많은 도움을 받고있습니다.
감사합니다.
제가 다른곳의 예제를 통해서 리스트뷰에 mysql에서 값을 가져와 뿌려주는것 까지 성공했으나
클릭했을때 해당 전화번호로 전화를 걸고 싶은데 눌러도 꼼짝을 안하네요.. 해쉬값으로 가져와서 그런건지..
어떻게 하면 될까요? 소스 첨부합니다 도와주세요 ㅠㅠ
public class MainActivity extends Activity {
String myJSON;
private static final String TAG_RESULTS = "result";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_MOBILE = "mobile";
JSONArray peoples = null;
ArrayList<HashMap<String,String>> personList;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.listView);
personList = new ArrayList<HashMap<String,String>>();
getData("http://192.168.0.5/getdata.php");
list.setOnItemClickListener(listener);
//task = new back();
//imView = (ImageView) findViewById(R.id.top);
//task.execute(imgUrl+"top.png");
ImageView imageView2 = (ImageView) findViewById(R.id.top);
Glide.with(this).load("http://192.168.0.5/image/top.png").into(imageView2);
ImageView imageView = (ImageView) findViewById(R.id.top2);
Glide.with(this).load("http://192.168.0.5/image/images.jpg").into(imageView);
}
public void banner1(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.naver.com"));
startActivity(intent);
}
//리스트뷰
protected void showList() {
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray(TAG_RESULTS);
for (int i = 0; i < peoples.length(); i++) {
JSONObject c = peoples.getJSONObject(i);
String id = c.getString(TAG_ID);
String name = c.getString(TAG_NAME);
String mobile = c.getString(TAG_MOBILE);
HashMap<String,String> persons = new HashMap<String,String>();
persons.put(TAG_ID, id);
persons.put(TAG_NAME, name);
persons.put(TAG_MOBILE, mobile);
personList.add(persons);
}
ListAdapter adapter = new SimpleAdapter(
MainActivity.this, personList, R.layout.list_item,
new String[]{TAG_ID, TAG_NAME, TAG_MOBILE},
new int[]{R.id.id, R.id.name, R.id.mobile}
);
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
OnItemClickListener listener = new OnItemClickListener() { // 이렇게 해주었는데 꼼짝을 안합니다!! 로그를 찍어보니 TAG_MOBILE은 단순히 mobile이라는 글씨를 스트링값으로 가져오는데.. 어떤걸 넣어줘야 전화걸기를 할 수 있을까요??? ㅠㅠㅠ
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
String strPhoneNumber = "tel:"+TAG_MOBILE;
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(strPhoneNumber));
startActivity(intent);
Log.d("onClick>>>", ""+strPhoneNumber);
}
};
public void getData(String url){
class GetDataJSON extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String uri = params[0];
BufferedReader bufferedReader = null;
try {
URL url = new URL(uri);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
StringBuilder sb = new StringBuilder();
bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String json;
while((json = bufferedReader.readLine())!= null){
sb.append(json+"\n");
}
return sb.toString().trim();
}catch(Exception e){
return null;
}
}
@Override
protected void onPostExecute(String result){
myJSON=result;
showList();
}
}
GetDataJSON g = new GetDataJSON();
g.execute(url);
}
public void call(View v){
String strPhoneNumber = "tel:"+TAG_MOBILE;
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(strPhoneNumber));
startActivity(intent);
Log.d("onClick>>>", ""+strPhoneNumber);
}
}