我创建了一个清单,并存储了小镇中一些最重要服务的列表以及电话的一些随机img。想法是,当用户按下它时,它将通过意图呼叫该号码。但是问题是我不知道我不知道如何调用该意图,但由于我不知道从何处拨打电话号码,将其存储在哪里,所以一切都瓦解了。...所有电话号码都不相同,因此增加了复杂性...
JAVA代码
package com.example.korisnik.indjijavodic;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import java.util.ArrayList;
public class Dobrodosli extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lista);
ArrayList<AndroidDobrodosli> androidDobrodosli = new ArrayList<>();
androidDobrodosli.add(new AndroidDobrodosli("Taksi stanica"));
androidDobrodosli.add(new AndroidDobrodosli("Autobuska stanica"));
androidDobrodosli.add(new AndroidDobrodosli("Zeleznicka stanica"));
androidDobrodosli.add(new AndroidDobrodosli("Turisticka agencija grada"));
androidDobrodosli.add(new AndroidDobrodosli("Policija"));
androidDobrodosli.add(new AndroidDobrodosli("Hitna pomoc"));
DobrodosliAdapter dobrodosliAdapter = new DobrodosliAdapter(this,androidDobrodosli);
ListView listView = findViewById(R.id.lista_brojeva);
listView.setAdapter(dobrodosliAdapter);
}
}
public class AndroidDobrodosli {
private String mInfo;
public int getmBrTelefona() {
return mBrTelefona;
}
private int mBrTelefona;
public String getmInfo() {
return mInfo;
}
public AndroidDobrodosli(String mInfo,int mBrTelefona) {
this.mInfo = mInfo;
this.mBrTelefona = mBrTelefona;
}
}
public class DobrodosliAdapter extends ArrayAdapter<AndroidDobrodosli> {
public DobrodosliAdapter(Dobrodosli dobrodosli, ArrayList<AndroidDobrodosli> androidDobrodosli) {
super(dobrodosli, 0, androidDobrodosli);
}
public View getView(int position, View convertView, ViewGroup parent) {
View listView = convertView;
if (listView == null) {
listView = LayoutInflater.from(getContext()).inflate(R.layout.dobrodosli, parent, false);
}
AndroidDobrodosli dobrodosli = getItem(position);
TextView brojTelefona = (TextView) listView.findViewById(R.id.broj_telefona);
brojTelefona.setText(dobrodosli.getmInfo());
return listView;
}
}
请不要告诉我有关SQL和存储信息的信息...这仍然超出我的范围
答案 0 :(得分:0)
使用您的代码...
设置arrayList时,将添加的内容更改为类似的数字。
androidDobrodosli.add(new AndroidDobrodosli("Taksi stanica","01234567890"));
当您设置onClick时,您将拥有该职位,因此您可以执行类似的操作来设置意图...
Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:"+androidDobrodsli.get(position).getmBrTelefona()); startActivity(intent);