如果单击textview,则应使用edittext打开alertdiaolg ...使用ok和cancel按钮进行警告对话..想要将edittext中的值显示为相同的textview。
public void showMessage(View v)
{
LayoutInflater li = LayoutInflater.from(context);
View promptsView = li.inflate(R.layout.prompts, null);
//final View textEntryView;
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set prompts.xml to alertdialog builder
alertDialogBuilder.setView(promptsView);
fourth = (TextView)findViewById(R.id.qty1);
final EditText userInput = (EditText)promptsView.findViewById(R.id.editTextDialogUserInput);
//String ed = userInput.getText().toString();
// set dialog message
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
String ed = userInput.getText().toString().trim();
// get user input and set it to result
// edit text
fourth.setText(userInput.getText());
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
我有一个带有onclickable的xml,列表中有一个textview
<TextView
android:id="@+id/qty1"
android:clickable="true"
android:gravity="center"
android:onClick="showMessage"
android:padding="3dip"
android:text="1.00"
android:textColor="#000000"
android:layout_gravity="right"
/>
如果我们单击列表中的textview,第一行正在更新,但不会保留在列表中。 列表
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting Array of Contacts
JSONArray contacts = json.getJSONArray("JSONDataResult");
if(contacts.length()!=0)
{
// looping through All Contacts
for(int i = 0; i < contacts.length(); i++){
JSONObject c = contacts.getJSONObject(i);
len1++;
// Storing each json item in variable
String id = c.getString(TAG_BARCODE);
String name = c.getString(TAG_SECTION);
String email = c.getString(TAG_MRP);
String address12 = c.getString(TAG_QTY);
barcode123[s1] = c.getString(TAG_BARCODE);
section123[s1]= c.getString(TAG_SECTION);
mrp123[s1] = c.getString(TAG_MRP);
qty123[s1] = c.getString(TAG_QTY);
}
s1++;
}else
{
Toast.makeText(getApplicationContext(), "Please enter valid Barcode", Toast.LENGTH_SHORT).show();
}
for(int temp=0;temp<=len1;temp++){
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_BARCODE, barcode123[temp]);
map.put(TAG_SECTION,section123[temp]);
map.put(TAG_MRP, mrp123[temp]);
map.put(TAG_QTY, qty123[temp]);
// adding HashList to ArrayList
contactList.add(map);
}
} catch (JSONException e) {
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.list_item,
new String[] { TAG_BARCODE, TAG_SECTION, TAG_MRP, TAG_QTY }, new int[] {
R.id.txt, R.id.txt1, R.id.mrp,R.id.qty1});
setListAdapter(adapter);
答案 0 :(得分:0)
要小心,因为EditText.getText()将返回Editable对象而不是String。尝试使用以下内容(假设您的textview是vsk评论的全局视图):
// get user input and set it to result edit text
fourth.setText(userInput.getText().toString());