我的应用程序有一个客户端数据列表视图。 listView中的每一行都将包含name,address,telNo等。我从webcall获取数据,然后使用要返回适配器的数据填充ArrayList。
当用户单击列表中的某行时,然后在适配器的onClick中,我获取电话号码并启动启动拨号器活动的意图。这一切都运作良好。
客户端的telno总是来自网络摄像头,但在视图中我有逻辑确定它是否显示。有些公司不希望显示客户编号,而其他公司则显示。
如何判断保存数字的TextView是否在运行时显示在视图中?我设置了一个标签,我传递给onclick,其中listView中的行已被点击,但我怎么能使用像
这样的东西if(Textview.isShown)
在onClick里面?我最终想要的是,如果文本视图显示保存数字,那么用户可以单击以拨打拨号器,否则拨号器将不拨号码(即使它出现在列表中,只是没有显示)。
先谢谢马特。
private class MySimpleArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final ArrayList<?> list;
public MySimpleArrayAdapter(Context context, ArrayList<?> list) {
super(context, R.layout.getrotadetailsrow);
Log.e(TAG, "inside adapter constructor");
this.context = context;
this.list = list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.getrotadetailsrow, parent,
false);
String record = list.get(position).toString();
String[] recordArray = record.split(",");
//recordArray[6] = ****the telephone number****
rowView.setTag(record);
TextView telNo = (TextView) rowView
.findViewById(R.id.telNo);
if(someCondition){
telNo.setText("TelNo: " + recordArray[6]);
}else{
telNo.setVisibility(View.GONE);
}
return rowView;
}
@Override
public int getCount() {
return this.list.size();
}
}//end of adapter
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String record = (String)view.getTag();
String[] itemsInRecord = record.split(",");
String telNo = itemsInRecord[6];
String numberToDial = "tel:" + telNo;
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(numberToDial)));
}
[EDIT1]
public class GetRotaDetails extends NfcBaseActivity implements OnItemClickListener{
ArrayList<ArrayList<String>> array;
private static final String TAG = GetRotaDetails.class.getSimpleName();
NfcScannerApplication nfcscannerapplication;
String callID;
ListView listView;
Intent intent;
MySimpleArrayAdapter arrayAdapter;
SharedPreferences appSharedPrefs;
Handler handler;
Runnable runnable;
String rotaAutoLogout;
int rotaAutoLogoutAsInt;
String postcodeToPassToDirections;
String postcodeWithoutSpaces;
public static final String CUSTOM_QRCODE_ACTION = "com.carefreegroup.QRCODE_ACTION";
String carerID;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
///////////set titlebar to carer's name///////////////////////
//////////////////////////////////////////////////////////////
nfcscannerapplication = (NfcScannerApplication) getApplication();
intent = this.getIntent();
setContentView(R.layout.getrotadetailslayout);
array = new ArrayList<ArrayList<String>>();
listView = (ListView) findViewById(R.id.getrotadetailslistview);
}// end of onCreate
private class AsyncGetRotaDetails extends AsyncTask<String, Void, String> {
ProgressDialog progressDialog;
String rotaDetails = null;
@Override
protected String doInBackground(String... params) {
try {
Log.e(TAG, "inside doInBackground");
rotaDetails = nfcscannerapplication.loginWebservice.getRotaDetail(params[0]);
} catch (Exception e) {
e.printStackTrace();
}
return rotaDetails;
}
@Override
protected void onPostExecute(String xmlResult) {
super.onPostExecute(xmlResult);
if (progressDialog != null)
progressDialog.dismiss();
RetrieveExtraDetails red = new RetrieveExtraDetails();
array = red.getExtraDetails(xmlResult);
Log.e(TAG, "array from WS = " + array.size());
if (arrayAdapter == null){
MySimpleArrayAdapter arrayAdapter = new MySimpleArrayAdapter(GetRotaDetails.this, array);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(GetRotaDetails.this);
}//end if
}// end of postExecute
}//end of Async
private class MySimpleArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final ArrayList<?> list;
public MySimpleArrayAdapter(Context context, ArrayList<?> list) {
super(context, R.layout.getrotadetailsrow);
Log.e(TAG, "inside adapter constructor");
this.context = context;
this.list = list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.getrotadetailsrow, parent,
false);
String record = list.get(position).toString();
String[] recordArray = record.split(",");
rowView.setTag(record);
TextView telNo = (TextView) rowView
.findViewById(R.id.telno);
if( someCondition ){
telNo.setVisibility(View.GONE);
}else {
telNo.setVisibility(View.VISIBLE);
telNo.setText("TelNo: " + recordArray[6]);
}
}
}
return rowView;
}
@Override
public int getCount() {
return this.list.size();
}
}//end of adapter
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String record = (String)view.getTag();
String[] itemsInRecord = record.split(",");
String telNo = itemsInRecord[6];
String numberToDial = "tel:" + telNo;
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(numberToDial)));
}
}// end of class
答案 0 :(得分:1)
您需要在列表项上单击
初始化textview @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
TextView tv = (TextView)view.findViewById(R.textView1);
if (tv.getVisibility() == View.VISIBLE) {
// Its visible
} else {
// Either gone or invisible
}
}
});
点击项目后,您可以将视图作为onItemClick
的参数。因此,使用视图对象初始化textview
TextView tv = (TextView)view.findViewById(R.textView1);
然后使用textview tv进行操作。