我编写了TabHost
从 Web 服务获取值的代码,并将这些值添加到TableRow
. 但是当我搜索用户时,我将值从微调器和文本框发送到 Web 服务,并根据我的请求获取值。
问题是我无法TableRow
通过创建 new fresh来添加TableRows
。谁能帮我找到我的代码中的任何错误。
public class Deleteuser extends Activity{
Webservicepath path= new Webservicepath();
TextView userId,Userrole;
CheckBox selectcheck;
Spinner utype;
ArrayList<DeleteuserDetails> userdetail= new ArrayList<DeleteuserDetails>();
DeleteuserDetails deleteuserDetail=new DeleteuserDetails();
alertbox alert=new alertbox();
EditText edtTxtUserId;
Button userId_show,btn_user_delete,spinner_user_search;
TableLayout userdetailTable;
TextView[] deleteuserList;
TextView uName,CreatedBy,CreatedDate;
String checkedValue,selecteduserType,userid;
LinearLayout linearLayout;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.delete_user);
utype=(Spinner)findViewById(R.id.spin_delete_userType);
userId_show=(Button)findViewById(R.id.btn_user_delete);
userdetailTable=(TableLayout)findViewById(R.id.delete_userDetails_Table);
edtTxtUserId=(EditText)findViewById(R.id.txt_user_delete);
spinner_user_search=(Button)findViewById(R.id.btn_spinner_user_search_select);
path.setNamespace();
path.setMethod_name("userList");
path.setSoap_action();
path.setUrl();
new deteUserIdLoad().execute();
utype.setId(10);
edtTxtUserId.setId(20);
userId_show.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new searchuser().execute();
}
});
spinner_user_search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new utypesearch().execute();
}
});
}
public class deteUserIdLoad extends AsyncTask<Void, Void, ArrayList<DeleteuserDetails>>{
Webservice service=new Webservice(path.getNamespace(), path.getMethod_name(), path.getUrl(), path.getSoap_action());
/* (non-Javadoc)
* @see android.os.AsyncTask#doInBackground(Params[])
*/
@Override
protected ArrayList<DeleteuserDetails> doInBackground(Void... arg0) {
// TODO Auto-generated method stub
try{
SoapObject request = service.getRequest();
SoapSerializationEnvelope envelope = service.getEnvelope(request);
SoapObject response = service.getResponse(envelope);
Log.i("Service Master", response.toString());
int count = response.getPropertyCount();
for (int i = 0; i < count; i++) {
SoapObject result = (SoapObject) response.getProperty(i);
DeleteuserDetails deleteuserDetails=new DeleteuserDetails();
if(result.getPropertyAsString(4)!=null){
deleteuserDetails.setUserId(result.getPropertyAsString(4));
}
else{
}
if(result.getPropertyAsString(2)!=null){
deleteuserDetails.setUserName(result.getPropertyAsString(2));
}
else{
}
if(result.getPropertyAsString(3)!=null){
deleteuserDetails.setUserRole(result.getPropertyAsString(3));
}
if(result.getPropertyAsString(1)!=null){
deleteuserDetails.setCreatedDate(result.getPropertyAsString(1));
}
else{
}
try {
deleteuserDetails.setCreatedBy(result.getPropertyAsString(0).toString());
}
catch(NullPointerException npe) {
deleteuserDetails.setCreatedBy("null");
}
userdetail.add(deleteuserDetails);
}
}
catch(Exception e){
e.printStackTrace();
}
return userdetail;
}
protected void onPostExecute(final ArrayList<DeleteuserDetails>deleteuserDetails) {
deleteuserList = new TextView[deleteuserDetails.size()];
for(int i=0;i<deleteuserDetails.size();i++){
TableRow deleteUserRow=new TableRow(Deleteuser.this);
deleteUserRow.setId(i);
deleteUserRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
selectcheck = new CheckBox(Deleteuser.this);
selectcheck.setId(i);
selectcheck.setTag(i);
deleteUserRow.addView(selectcheck);
deleteuserList[i]=new TextView(Deleteuser.this);
deleteuserList[i].setId(i);
deleteuserList[i].setTag(i);
deleteuserList[i].setText(deleteuserDetails.get(i).getUserId());
deleteUserRow.addView(deleteuserList[i]);
uName=new TextView(Deleteuser.this);
uName.setId(i);
uName.setText(deleteuserDetails.get(i).getUserName());
deleteUserRow.addView(uName);
Userrole=new TextView(Deleteuser.this);
Userrole.setId(i);
Userrole.setPadding(20, 0, 0, 0);
Userrole.setText(deleteuserDetails.get(i).getUserRole());
deleteUserRow.addView(Userrole);
CreatedDate=new TextView(Deleteuser.this);
CreatedDate.setId(i);
CreatedDate.setPadding(20, 0, 0, 0);
CreatedDate.setText(deleteuserDetails.get(i).getCreatedDate());
deleteUserRow.addView(CreatedDate);
CreatedBy=new TextView(Deleteuser.this);
CreatedBy.setId(i);
CreatedBy.setPadding(20, 0, 0, 0);
CreatedBy.setText(deleteuserDetails.get(i).getCreatedBy());
deleteUserRow.addView(CreatedBy);
userdetailTable.addView(deleteUserRow,
new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
selectcheck.setOnClickListener(listener);
Log.i("Exception",""+i);
}
TableRow addcomponentrow=new TableRow(Deleteuser.this);
addcomponentrow.setId(200);
addcomponentrow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
Button Deletecomponentbtn=new Button(Deleteuser.this);
Deletecomponentbtn.setText("Delete");
Deletecomponentbtn.setId(200);
Deletecomponentbtn.setPadding(10, 0, 20, 2);
Deletecomponentbtn.setBackgroundColor(color.red);
addcomponentrow.addView(Deletecomponentbtn);
userdetailTable.addView(addcomponentrow,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
Deletecomponentbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new DeleteUserid().execute(checkedValue);
}
});
}
final OnClickListener listener=new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int index = (Integer) v.getTag();
checkedValue=(String) deleteuserList[index].getText();
}
};
}
public class DeleteUserid extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
path.setNamespace();
path.setUrl();
path.setMethod_name("deleteuser");
path.setSoap_action();
selecteduserType=String.valueOf(utype.getSelectedItem());
userid=edtTxtUserId.getText().toString();
Log.i("selected user",selecteduserType);
Log.i("userid",userid);
Webservice service=new Webservice(path.getNamespace(), path.getMethod_name(), path.getUrl(), path.getSoap_action());
SoapObject deleteUser=service.getRequest();
PropertyInfo delete_userid=new PropertyInfo();
delete_userid.setName("UID");
delete_userid.setValue(checkedValue);
deleteUser.addProperty(delete_userid);
SoapSerializationEnvelope delete_userid_envelope=service.getEnvelope(deleteUser);
SoapPrimitive response=service.getsoapprimitive(delete_userid_envelope);
Log.d("UserId Deletee","res"+response);
return response.toString();
}
protected void onPostExecute(String res){
if(res.equals("true"))
{
Toast.makeText(Deleteuser.this,checkedValue+ "User Deleted Successfully", 20).show();
userdetailTable.removeAllViews();
new deteUserIdLoad().execute();
}
else
{
alert.generateAlert(Deleteuser.this,"Deletion Failed","Operation Failed",null);
}
}
}
public class searchuser extends AsyncTask<Void, Void,ArrayList<DeleteuserDetails>>{
@Override
protected ArrayList<DeleteuserDetails> doInBackground(Void... arg0) {
// TODO Auto-generated method stub
path.setNamespace();
path.setMethod_name("searchuser");
path.setSoap_action();
path.setUrl();
selecteduserType=String.valueOf(utype.getSelectedItem());
userid=edtTxtUserId.getText().toString();
if(!String.valueOf(utype.getSelectedItem()).equals("select")){
Webservice service=new Webservice(path.getNamespace(), path.getMethod_name(), path.getUrl(), path.getSoap_action());
try{
SoapObject searchUser=service.getRequest();
PropertyInfo search_userid=new PropertyInfo();
search_userid.setName("userID");
search_userid.setValue(userid);
searchUser.addProperty(search_userid);
/* PropertyInfo search_utype=new PropertyInfo();
search_utype.setName("utype");
search_utype.setValue(selecteduserType);
searchUser.addProperty(search_utype);*/
SoapSerializationEnvelope envelope = service.getEnvelope(searchUser);
SoapObject response = service.getResponse(envelope);
int count = response.getPropertyCount();
if(userdetail.size()>0){
userdetail.clear();
}
for (int i = 0; i < count; i++) {
SoapObject result = (SoapObject) response.getProperty(i);
DeleteuserDetails deleteuserDetails=new DeleteuserDetails();
if(result.getPropertyAsString(4)!=null){
deleteuserDetails.setUserId(result.getPropertyAsString(4));
}
else{
}
if(result.getPropertyAsString(2)!=null){
deleteuserDetails.setUserName(result.getPropertyAsString(2));
}
else{
}
if(result.getPropertyAsString(3)!=null){
deleteuserDetails.setUserRole(result.getPropertyAsString(3));
}
if(result.getPropertyAsString(1)!=null){
deleteuserDetails.setCreatedDate(result.getPropertyAsString(1));
}
else{
}
try {
deleteuserDetails.setCreatedBy(result.getPropertyAsString(0).toString());
}
catch(NullPointerException npe) {
deleteuserDetails.setCreatedBy("null");
}
userdetail.add(deleteuserDetails);
}
}
catch(Exception e){
e.printStackTrace();
}
}
else{
alert.generateAlert(Deleteuser.this,"Please Enter a valid Mobile Number", "Mobile Number Required",R.drawable.noicon);
}
return userdetail;
}
protected void onPostExecute(ArrayList<DeleteuserDetails> deleteuserDetails) {
deleteuserList = new TextView[deleteuserDetails.size()];
for(int i=0;i<deleteuserDetails.size();i++){
TableRow deleteUserRow=new TableRow(Deleteuser.this);
deleteUserRow.setId(i);
deleteUserRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
selectcheck = new CheckBox(Deleteuser.this);
selectcheck.setId(i);
selectcheck.setTag(i);
deleteUserRow.addView(selectcheck);
deleteuserList[i]=new TextView(Deleteuser.this);
// deleteuserList[i].setId(i);
deleteuserList[i].setTag(i);
deleteuserList[i].setText(deleteuserDetails.get(i).getUserId());
deleteUserRow.addView(deleteuserList[i]);
uName=new TextView(Deleteuser.this);
uName.setId(i);
uName.setText(deleteuserDetails.get(i).getUserName());
deleteUserRow.addView(uName);
Userrole=new TextView(Deleteuser.this);
Userrole.setId(i);
Userrole.setPadding(20, 0, 0, 0);
Userrole.setText(deleteuserDetails.get(i).getUserRole());
deleteUserRow.addView(Userrole);
CreatedDate=new TextView(Deleteuser.this);
CreatedDate.setId(i);
CreatedDate.setPadding(20, 0, 0, 0);
CreatedDate.setText(deleteuserDetails.get(i).getCreatedDate());
deleteUserRow.addView(CreatedDate);
CreatedBy=new TextView(Deleteuser.this);
CreatedBy.setId(i);
CreatedBy.setPadding(20, 0, 0, 0);
CreatedBy.setText(deleteuserDetails.get(i).getCreatedBy());
deleteUserRow.addView(CreatedBy);
userdetailTable.addView(deleteUserRow,
new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
selectcheck.setOnClickListener(listener);
Log.i("Exception",""+i);
}
TableRow addcomponentrow=new TableRow(Deleteuser.this);
addcomponentrow.setId(200);
addcomponentrow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
Button Deletecomponentbtn=new Button(Deleteuser.this);
Deletecomponentbtn.setText("Delete");
Deletecomponentbtn.setId(200);
Deletecomponentbtn.setPadding(10, 0, 20, 2);
Deletecomponentbtn.setBackgroundColor(color.red);
addcomponentrow.addView(Deletecomponentbtn);
userdetailTable.addView(addcomponentrow,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
Deletecomponentbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new DeleteUserid().execute(checkedValue);
}
});
}
final OnClickListener listener=new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int index = (Integer) v.getTag();
checkedValue=(String) deleteuserList[index].getText();
}
};
}
public class utypesearch extends AsyncTask<Void, Void, ArrayList<DeleteuserDetails> >{
@Override
protected ArrayList<DeleteuserDetails> doInBackground(Void... arg0) {
// TODO Auto-generated method stub
path.setNamespace();
path.setMethod_name("searchuser");
path.setSoap_action();
path.setUrl();
Webservice service=new Webservice(path.getNamespace(), path.getMethod_name(), path.getUrl(), path.getSoap_action());
selecteduserType=String.valueOf(utype.getSelectedItem());
try{
SoapObject searchusertype=service.getRequest();
PropertyInfo search_userid=new PropertyInfo();
search_userid.setName("utype");
search_userid.setValue(selecteduserType);
searchusertype.addProperty(search_userid);
SoapSerializationEnvelope envelope = service.getEnvelope(searchusertype);
SoapObject response = service.getResponse(envelope);
int count = response.getPropertyCount();
if(userdetail.size()>0){
userdetail.clear();
}
for (int i = 0; i < count; i++) {
SoapObject result = (SoapObject) response.getProperty(i);
DeleteuserDetails deleteuserDetails=new DeleteuserDetails();
if(result.getPropertyAsString(4)!=null){
deleteuserDetails.setUserId(result.getPropertyAsString(4));
}
else{
}
if(result.getPropertyAsString(2)!=null){
deleteuserDetails.setUserName(result.getPropertyAsString(2));
}
else{
}
if(result.getPropertyAsString(3)!=null){
deleteuserDetails.setUserRole(result.getPropertyAsString(3));
}
if(result.getPropertyAsString(1)!=null){
deleteuserDetails.setCreatedDate(result.getPropertyAsString(1));
}
else{
}
try {
deleteuserDetails.setCreatedBy(result.getPropertyAsString(0).toString());
}
catch(NullPointerException npe) {
deleteuserDetails.setCreatedBy("null");
}
userdetail.add(deleteuserDetails);
}
}
catch(Exception e){
e.printStackTrace();
}
return userdetail;
}
protected void onPostExecute(ArrayList<DeleteuserDetails> deleteuserDetails) {
deleteuserList = new TextView[deleteuserDetails.size()];
for(int i=0;i<deleteuserDetails.size();i++){
TableRow deleteUserRow=new TableRow(Deleteuser.this);
deleteUserRow.setId(i);
deleteUserRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
selectcheck = new CheckBox(Deleteuser.this);
selectcheck.setId(i);
selectcheck.setTag(i);
deleteUserRow.addView(selectcheck);
deleteuserList[i]=new TextView(Deleteuser.this);
// deleteuserList[i].setId(i);
deleteuserList[i].setTag(i);
deleteuserList[i].setText(deleteuserDetails.get(i).getUserId());
deleteUserRow.addView(deleteuserList[i]);
uName=new TextView(Deleteuser.this);
uName.setId(i);
uName.setText(deleteuserDetails.get(i).getUserName());
deleteUserRow.addView(uName);
Userrole=new TextView(Deleteuser.this);
Userrole.setId(i);
Userrole.setPadding(20, 0, 0, 0);
Userrole.setText(deleteuserDetails.get(i).getUserRole());
deleteUserRow.addView(Userrole);
CreatedDate=new TextView(Deleteuser.this);
CreatedDate.setId(i);
CreatedDate.setPadding(20, 0, 0, 0);
CreatedDate.setText(deleteuserDetails.get(i).getCreatedDate());
deleteUserRow.addView(CreatedDate);
CreatedBy=new TextView(Deleteuser.this);
CreatedBy.setId(i);
CreatedBy.setPadding(20, 0, 0, 0);
CreatedBy.setText(deleteuserDetails.get(i).getCreatedBy());
deleteUserRow.addView(CreatedBy);
userdetailTable.addView(deleteUserRow,
new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
selectcheck.setOnClickListener(listener);
Log.i("Exception",""+i);
}
TableRow addcomponentrow=new TableRow(Deleteuser.this);
addcomponentrow.setId(200);
addcomponentrow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
Button Deletecomponentbtn=new Button(Deleteuser.this);
Deletecomponentbtn.setText("Delete");
Deletecomponentbtn.setId(200);
Deletecomponentbtn.setPadding(10, 0, 20, 2);
Deletecomponentbtn.setBackgroundColor(color.red);
addcomponentrow.addView(Deletecomponentbtn);
userdetailTable.addView(addcomponentrow,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
Deletecomponentbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new DeleteUserid().execute(checkedValue);
}
});
}
final OnClickListener listener=new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int index = (Integer) v.getTag();
checkedValue=(String) deleteuserList[index].getText();
}
};
}
}
LOGCAT
12-27 14:29:36.160: W/WindowManager(59): Key dispatching timed out sending to com.mvss.pack/com.mvss.pack.UserCreation
12-27 14:29:36.160: W/WindowManager(59): Previous dispatch state: null
12-27 14:29:36.160: W/WindowManager(59): Current dispatch state: {{null to Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false} @ 1356598776162 lw=Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false} lb=android.os.BinderProxy@4606cc18 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false}}}
12-27 14:29:36.160: W/WindowManager(59): Continuing to wait for key to be dispatched
12-27 14:29:41.169: W/WindowManager(59): Key dispatching timed out sending to com.mvss.pack/com.mvss.pack.UserCreation
12-27 14:29:41.169: W/WindowManager(59): Previous dispatch state: null
12-27 14:29:41.169: W/WindowManager(59): Current dispatch state: {{null to Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false} @ 1356598781172 lw=Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false} lb=android.os.BinderProxy@4606cc18 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false}}}
12-27 14:29:41.169: W/WindowManager(59): Continuing to wait for key to be dispatched
12-27 14:29:46.179: W/WindowManager(59): Key dispatching timed out sending to com.mvss.pack/com.mvss.pack.UserCreation
12-27 14:29:46.179: W/WindowManager(59): Previous dispatch state: null
12-27 14:29:46.179: W/WindowManager(59): Current dispatch state: {{null to Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false} @ 1356598786183 lw=Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false} lb=android.os.BinderProxy@4606cc18 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false}}}
12-27 14:29:46.179: W/WindowManager(59): Continuing to wait for key to be dispatched
12-27 14:29:51.190: W/WindowManager(59): Key dispatching timed out sending to com.mvss.pack/com.mvss.pack.UserCreation
12-27 14:29:51.190: W/WindowManager(59): Previous dispatch state: null
12-27 14:29:51.190: W/WindowManager(59): Current dispatch state: {{null to Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false} @ 1356598791192 lw=Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false} lb=android.os.BinderProxy@4606cc18 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{4604d328 com.mvss.pack/com.mvss.pack.UserCreation paused=false}}}
12-27 14:29:51.190: W/WindowManager(59): Continuing to wait for key to be dispatched
12-27 14:30:23.919: W/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@45fca1b0
问题是它不会引发任何异常或强制关闭。