当我点击Android中的列表视图行项时,如何获取按钮处于活动状态并传递列表视图项可能性

时间:2016-01-19 10:41:48

标签: android

我在列表视图上工作,在此列表视图中有多个按钮,如删除,编辑等。我的列表视图活动正常,列表视图项从MySQL数据库中检索。我的问题是,最初加载列表视图项时所有按钮都被取消激活,当我点击列表视图行项目时,所有按钮都被激活并获得列表视图项目位置,按钮被放置在不同布局的列表视图屏幕中,之后,当我按下编辑按钮时,它会在编辑文本字段中显示另一个带有行项目的活动以进行编辑,如何解决我的问题。

请帮帮我..

谢谢&问候。

这是我的列表视图

final ListView lv = getListView();

    // on seleting single product

    // launching Edit Product Screen
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

            Toast.makeText(Waiting_ListViewActivity.this, "ITEM PRESSED" + position, Toast.LENGTH_SHORT).show();

//****************************EDIT BUTTON****************************************


            modify=(Button)findViewById(R.id.modify);
    //      modify.setTag(position);
            modify.setEnabled(true);
            modify.setOnClickListener(new View.OnClickListener() {



        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub



            if (Get_Wi_Fi_State() == false && (!tabname.equals("emulator")))
            {
                // Do whatever
                showMessageBox("Notification.....!!", " Please Connect to Wi-Fi Network");
            }
            else
            {
        //       int position = (Integer) v.getTag();

                View parent = (View) v.getParent();
                ListView lv = (ListView) parent.getParent();
                final int position = lv.getPositionForView(parent);

                exit.setEnabled(false); 
                sms.setEnabled(false);
                waiting.setEnabled(false);

                Intent i = new Intent(getApplicationContext(),Waiting_ModifyActivity.class);
                // sending Srno to next activity
                i.putExtra(TAG_SRNO, SRNO);
                i.putExtra(TAG_NAME, NAME);
                i.putExtra(TAG_MOBILE, MOB);
                i.putExtra(TAG_NO_OF_PERSON, NOOFPERSON);
                i.putExtra(TAG_SEATING_AREA, SEATINGAREA);
                startActivity(i);
                exit.setEnabled(true);  
                sms.setEnabled(true);
                waiting.setEnabled(true);
                delete.setEnabled(true);

                }
        }
    });     

这是我的Waiting_ModifyActivity.class ...

public class Waiting_ModifyActivity  extends Activity implements menudatabse,OnClickListener{

EditText PersonSrno;
EditText PersonName;
EditText NoOfPerson;
EditText SeatingArea;
EditText PersonMobNo;
EditText persono;
EditText PersonTableNo;
EditText SendSMS;

Button btnUpdate;
Button btnDelete;
Button btnExit;
Button btnSend;
String NAME; 
private String MOB;
private String NOOFPERSON;
private String SEATINGAREA;
String SRNO;


// Progress Dialog
private ProgressDialog pDialog;

// JSON parser class
JSONParser jsonParser = new JSONParser();

// products JSONArray
JSONArray products = null;

private Dialog dialog;
ProgressDialog PD;

final Context context = this;
ArrayList<HashMap<String, String>> productsList;




// single product url
private static String url_SingleRow_table = "http://192.168.1.198/android_connect/get_single_row.php";


// url to update product
private static String url_Updateistview_table = "http://192.168.1.198/android_connect/update_row.php";




// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCTS = "products";
//    private static final String TAG_PID = "pid";
private static final String TAG_SRNO = "SRNO";  // These are the same as php file name which should be pass is SRNO,NAME,MOBILE_NO 
private static final String TAG_NAME = "NAME";
private static final String TAG_MOBILE = "MOBILE_NO";
private static final String TAG_NO_OF_PERSON = "NO_OF_PERSON"; 
private static final String TAG_DATE = "WAIT_DATE";
private static final String TAG_TIME = "WAIT_TIME";
private static final String TAG_SEATING_AREA = "SEATING_AREA";
//  private static final String TAG_PREFER_AREA = "SEATING_AREA";


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.waitlist_modify);

    //************************************EXIT BUTTON CODE************************* 
    btnExit= (Button) findViewById(R.id.btnExit);
    btnExit.setEnabled(true);
    btnExit.setOnClickListener(new OnClickListener() 
    {

        @Override
        public void onClick(View arg0)
        {

            finish();
            // TODO Auto-generated method stub
        //  System.exit(0); 
            //setContentView(R);
        }
    });


    // save button
    btnUpdate = (Button) findViewById(R.id.btnUpdate);

    // getting product details from intent
    Intent i = getIntent();

    // getting product id (srno) from intent    
    SRNO = i.getStringExtra(TAG_SRNO);  
    NAME = i.getStringExtra(TAG_NAME);
    MOB = i.getStringExtra(TAG_MOBILE);
    NOOFPERSON = i.getStringExtra(TAG_NO_OF_PERSON);
    SEATINGAREA = i.getStringExtra(TAG_SEATING_AREA);



    // Getting complete product details in background thread
    new GetProductDetails().execute();


    // save button click event
    btnUpdate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // starting background task to update product
            new UpdateProductDetails().execute();
        }
    });


}



//******************************Get Single row details**************************************************

/**
 * Background Async Task to Get complete product details
 * */
class GetProductDetails extends AsyncTask<String, String, String>{
    protected ArrayList<HashMap<String, String>> mylist;


    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Waiting_ModifyActivity.this);
        pDialog.setMessage("Loading List details. Please wait...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    /**
     * Getting product details in background thread
     * */
    protected String doInBackground(String... params) {

        // updating UI from Background Thread
        runOnUiThread(new Runnable() {
            private String[] srno;

            public void run() {
                // Check for success tag
                //int success;
                try {
                    PersonName = (EditText) findViewById(R.id.editText1);
                    PersonMobNo = (EditText)findViewById(R.id.editText2);
                    NoOfPerson = (EditText) findViewById(R.id.editText3);
                    SeatingArea = (EditText)findViewById(R.id.editText4);

                    PersonName.setText(NAME);
                    PersonMobNo.setText(MOB);
                    NoOfPerson.setText(NOOFPERSON);
                    SeatingArea.setText(SEATINGAREA);

                }

            catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    return null;
}


/**
 * After completing background task Dismiss the progress dialog
 * **/
protected void onPostExecute(String file_url) {
    // dismiss the dialog once got all details
    pDialog.dismiss();
}
}       





//*******************************************Update Details************************************

/**
 * Background Async Task to  Save product Details
 * */
class UpdateProductDetails extends AsyncTask<String, String, String> {

    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Waiting_ModifyActivity.this);
        pDialog.setMessage("Update Waiting List....");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    /**
     * Saving product
     * */
    protected String doInBackground(String... args) {

        // getting updated data from EditTexts

        String NAME= PersonName.getText().toString();
        String MOBILE_NO = PersonMobNo.getText().toString();
        String NO_OF_PERSON = NoOfPerson.getText().toString();
        String SEATING_AREA = SeatingArea.getText().toString();

        /*      String name = txtName.getText().toString();
        String price = txtPrice.getText().toString();
        String description = txtDesc.getText().toString();
         */
        // Building Parameters

        List<NameValuePair> postParameters = new ArrayList<NameValuePair>();

        postParameters.add(new BasicNameValuePair(TAG_SRNO,SRNO));

        postParameters.add(new BasicNameValuePair(TAG_NAME,NAME));
        postParameters.add(new BasicNameValuePair(TAG_MOBILE,MOBILE_NO));
        postParameters.add(new BasicNameValuePair(TAG_NO_OF_PERSON,NO_OF_PERSON));
        postParameters.add(new BasicNameValuePair(TAG_SEATING_AREA,SEATING_AREA));

        /*postParameters.add(new BasicNameValuePair("NAME",personname));
        postParameters.add(new BasicNameValuePair("MOBILE",personmobno));
        postParameters.add(new BasicNameValuePair("NO_OF_PERSON",noOfperson));
        postParameters.add(new BasicNameValuePair("PREFER_AREA",seatingarea));*/

        /*List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair(TAG_PID, pid));
        params.add(new BasicNameValuePair(TAG_NAME, name));
        params.add(new BasicNameValuePair(TAG_PRICE, price));
        params.add(new BasicNameValuePair(TAG_DESCRIPTION, description));*/

        // sending modified data through http request
        // Notice that update product url accepts POST method

        JSONObject json = jsonParser.makeHttpRequest(url_Updateistview_table,"POST", postParameters);

        // check json success tag
        try {
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                // successfully updated1
                Intent i = getIntent();
                // send result code 100 to notify about product update
                setResult(100, i);
                finish();
            } else {
                // failed to update product
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }


    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog once product uupdated
        pDialog.dismiss();
    }
}



@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}



}  // This Bracket is use for ie (extend Activity Line)

1 个答案:

答案 0 :(得分:0)

在模型类中添加额外的布尔字段。最初是假的,当用户点击列表项时将其设置为true并调用notifydatasetchanged();

getView方法的另一面检查此布尔变量是否为true然后激活所有按钮,否则保持不活动状态。