问题描述
- 和listview同一layout的按钮被复制
-
这是显示的代码
public void Infoshow()
{
setContentView(R.layout.companyinfo);//Button m_back =(Button)findViewById(R.id.button1); // GridView gv=(GridView)findViewById(R.id.se1); ListView gv=(ListView)findViewById(R.id.listView1); //List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>(); // list=new DB().CompanyInfo(myOrderCode); //list=new DB().CompanyInfo(searchwhere); SimpleAdapter adapter = new SimpleAdapter( MainActivity.this, //this, list, R.layout.companyinfo, new String[] { "OrderCode", "ProductName_CN", "ProductName_JP" ,"OrderNum"}, new int[] { R.id.txt_OrderCode, R.id.txt_ProductName_CN, R.id.txt_ProductName_JP , R.id.txt_OrderNum}); gv.setAdapter(adapter);
这是页面布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffcc"<FrameLayout android:layout_width="fill_parent" android:layout_height="40dip"
<TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginBottom="0dip" android:layout_marginLeft="0dip" android:layout_marginTop="0dip" android:gravity="center" android:text="详细信息" android:textSize="20dip" android:textStyle="bold" > </TextView> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical|right" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="返回" /> </LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginLeft="7dip"
android:layout_marginRight="7dip"
android:layout_marginTop="4dip"
android:layout_marginBottom="4dip"> <TextView android:id="@+id/txt_OrderCode" android:layout_width="80dp" android:layout_height="wrap_content" android:gravity="center" android:height="40dp" android:text="合同" android:textSize="14sp" /> <TextView android:id="@+id/txt_ProductName_CN" android:layout_width="80dp" android:layout_height="wrap_content" android:gravity="center" android:height="40dp" android:text="名称" android:textSize="14sp" /> <TextView android:id="@+id/txt_ProductName_JP" android:layout_width="80dp" android:layout_height="wrap_content" android:gravity="center" android:height="40dp" android:text="公司" android:textSize="14sp" /> <TextView android:id="@+id/txt_OrderNum" android:layout_width="80dp" android:layout_height="wrap_content" android:gravity="center" android:height="40dp" android:text="数量" android:textSize="14sp" /> </LinearLayout>
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
解决方案
解决方案二:
你这分activity的layout和listview的item了吗?怎么看着像是没有区分layout和item这两种布局方式
setContentView(R.layout.companyinfo);//这里是companyinfo布局
SimpleAdapter adapter = new SimpleAdapter(
MainActivity.this,
//this,
list,
R.layout.companyinfo, //item也是companyinfo布局
解决方案三:
应该如何去修改
这是主函数:
```package com.example.login_0508;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
//import com.bn.lb.client.RootActivity;
//import com.bn.lb.client.WhichView;
//import com.bottle.stockmanage.MainActivity;
//import com.bottle.stockmanage.R;
//import com.bottle.stockmanage.MainActivity;
//import com.bottle.stockmanage.R;
import android.R.string;
import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.StrictMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
//private List<? extends Map> VeCompanyInfo=new Vector(); //记录公司信息
public ListView listView;
private SimpleAdapter adapter;
private String myOrderCode;
private ArrayList searchwhere=new ArrayList();
private List> list = new ArrayList>();
//WhichView curr;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//验证账号密码
final EditText ID =(EditText)findViewById(R.id.editText1 );
final EditText PW =(EditText)findViewById(R.id .editText2 );
Button m_Ok=(Button)findViewById(R.id.button1 );
Button m_Cancel=(Button)findViewById(R.id .button2 );
//确定按钮监听
m_Ok.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String m_ID=ID.getText().toString().trim();
String m_PW=PW.getText().toString().trim();
String sql_PW=new DB().PassWord(m_ID);
if (sql_PW!=null)
{
if (m_PW.equals(sql_PW))
{
// Toast.makeText
// (
// MainActivity.this,
// "登陆成功",
// Toast.LENGTH_SHORT
// ).show();
//跳转查询画面
Searchwhere();
//setContentView(R.layout.searchwhere);
}
else
{
Toast.makeText(
MainActivity.this,
"用户名或密码不正确",
Toast.LENGTH_SHORT
).show();
}
}
else
{
Toast.makeText(
MainActivity.this,
"登录失败",
Toast.LENGTH_SHORT
).show();
}
}
});
m_Cancel.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//结束程序
System.exit(0);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
//查询画面
public void Searchwhere(){
setContentView(R.layout.searchwhere);
Button btn_Ok =(Button)findViewById(R.id.button1);
final EditText OrderCode=(EditText)findViewById(R.id.editText1);
final EditText CompName=(EditText)findViewById(R.id.editText2);
btn_Ok.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//String m_OrderCode=OrderCode.getText().toString().trim();
//myOrderCode=m_OrderCode;
searchwhere.clear();
searchwhere.add(OrderCode.getText().toString().trim());
searchwhere.add(CompName.getText().toString().trim());
list=new DB().CompanyInfo(searchwhere);
if (list.size()!=0)
{
Infoshow();
}
else
{
Toast.makeText(
MainActivity.this,
"没有符合条件的数据",
Toast.LENGTH_SHORT
).show();
}
}
});
}
//信息显示
public void Infoshow()
{
setContentView(R.layout.companyinfo);
//Button m_back =(Button)findViewById(R.id.button1);
// GridView gv=(GridView)findViewById(R.id.se1);
ListView gv=(ListView)findViewById(R.id.listView1);
//List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
// list=new DB().CompanyInfo(myOrderCode);
//list=new DB().CompanyInfo(searchwhere);
SimpleAdapter adapter = new SimpleAdapter(
MainActivity.this,
//this,
list,
R.layout.companyinfo,
new String[] { "OrderCode", "ProductName_CN", "ProductName_JP" ,"OrderNum"},
new int[] { R.id.txt_OrderCode, R.id.txt_ProductName_CN, R.id.txt_ProductName_JP , R.id.txt_OrderNum});
gv.setAdapter(adapter);
//返回键监控
//
// m_back.setOnClickListener(new OnClickListener(){
//
// @Override
// public void onClick(View v) {
// // TODO Auto-generated method stub
// Searchwhere();
// }
//
// });
//
}
}
这是取数据代码
package com.example.login_0508;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import com.example.login_0508.R.string;
public class DB {
ArrayList arraylist=new ArrayList();
ArrayList brraylist=new ArrayList();
ArrayList crraylist=new ArrayList();
HttpCon con=new HttpCon();
//取得密码
public String PassWord(String ID)
{
String result=null;
arraylist.clear();
brraylist.clear();
arraylist.add("ID");
brraylist.add(ID);
crraylist=con.GetWebServre("PassWord", arraylist, brraylist);
if(crraylist.size()!=0)
{
result=crraylist.get(0);
}
return result;
}
//取得公司信息
// public List> CompanyInfo(String OrderCode) {
// {
// //Vector result=new Vector();
// List> list = new ArrayList>();
// arraylist.clear();
// brraylist.clear();
// arraylist.add("OrderCode");
// brraylist.add(OrderCode);
// crraylist=con.GetWebServre("CompanyInfo", arraylist, brraylist);
//
// for (int j = 0; j < crraylist.size(); j += 4) {
// HashMap hashMap = new HashMap();
// hashMap.put("OrderCode", crraylist.get(j));
// hashMap.put("CompanyName", crraylist.get(j + 1));
// hashMap.put("CompanyTel", crraylist.get(j + 2));
// hashMap.put("Addr", crraylist.get(j + 3));
// list.add(hashMap);
// }
//
// return list;
//
// }
public List> CompanyInfo(ArrayList searchwhere) {
{
//Vector result=new Vector();
List> list = new ArrayList>();
arraylist.clear();
brraylist.clear();
arraylist.add("OrderCode");
brraylist.add((String) searchwhere.get(0));
arraylist.add("CompanyName");
brraylist.add((String) searchwhere.get(1));
crraylist=con.GetWebServre("CompanyInfo", arraylist, brraylist);
if(crraylist!=null)
{
for (int j = 0; j < crraylist.size(); j += 4) {
HashMap hashMap = new HashMap();
hashMap.put("OrderCode", crraylist.get(j));
hashMap.put("ProductName_JP", crraylist.get(j + 1));
hashMap.put("ProductName_CN", crraylist.get(j + 2));
hashMap.put("OrderNum", crraylist.get(j + 3));
list.add(hashMap);
}
}
return list;
}
}
}
这是查询画面代码
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="145dp"
android:text="合同号" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="68dp"
android:text="客户名称" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/editText1"
android:ems="10" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_marginRight="22dp"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:text="查询" />
这是信息显示代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffcc"
<FrameLayout android:layout_width="fill_parent" android:layout_height="40dip"
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="0dip"
android:layout_marginLeft="0dip"
android:layout_marginTop="0dip"
android:gravity="center"
android:text="详细信息"
android:textSize="20dip"
android:textStyle="bold" >
</TextView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical|right"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="返回" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginLeft="7dip"
android:layout_marginRight="7dip"
android:layout_marginTop="4dip"
android:layout_marginBottom="4dip"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/txt_OrderCode"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:height="40dp"
android:text="合同"
android:textSize="14sp" />
<TextView
android:id="@+id/txt_ProductName_CN"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:height="40dp"
android:text="名称"
android:textSize="14sp" />
<TextView
android:id="@+id/txt_ProductName_JP"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:height="40dp"
android:text="公司"
android:textSize="14sp" />
<TextView
android:id="@+id/txt_OrderNum"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:height="40dp"
android:text="数量"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>