0

如果单击 textview,alertdiaolg 应该打开 edittext...alert 对话框,带有确定和取消按钮..想要显示从 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"
                />

如果我们单击列表中的文本视图,则第一行正在更新,但未保留在列表中.. 列表

 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);
4

1 回答 1

0

请小心,因为EditText.getText()将返回可编辑对象而不是字符串。尝试以下操作(假设您的 textview 像 vsk 评论的那样是全局的):

// get user input and set it to result edit text
   fourth.setText(userInput.getText().toString());
于 2013-07-03T14:50:05.283 回答