foreach (ListViewItem itemRow in listView1.Items)
{
for (int i = 0; i < itemRow.SubItems.Count; i++)
{
string dueDate = itemRow.SubItems[i].Text;
MessageBox.Show(dueDate);
}
}
Andoroid怎么样? 在Baseadapter? 我的代码运行正常, 首先获取所有记录并列出带有textview的列表视图。 我处理(在一个适配器类中)单击事件id,名称..等等和setText项目插入数据库这里没问题但是; 如果我按下后退按钮并重新加载此页面,则丢失项目
我的主要java:
String query = "select * from xx where xxx = '" + xxx + "'";
PreparedStatement ps = con.prepareStatement(query);
ResultSet rs = ps.executeQuery();
listView = (ListView) findViewById(R.id.listView);
while (rs.next()) {
lst.add(new lt(rs.getString("xx"), rs.getString("xx").toString(), 1));
}
myAdaptor adaptor = new myAdaptor(this, lyt);
listView.setAdapter(adaptor);
主要布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="30dp"
android:textSize="20dp"
android:text="Table"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="#000000"
android:background="@drawable/bg"
android:id="@+id/txtmasaad"
/>
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:paddingBottom="5dp"/>
<Button
android:text="Okey"
android:id="@+id/btnonay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="35sp"
android:textColor="#ffffff"
android:background="@drawable/btnk"
android:textStyle="bold"
android:layout_marginBottom="5dp"/>
<Button
android:text="Go back"
android:id="@+id/btngeri"
android:textSize="35sp"
android:background="@drawable/btnb"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
myAdapter类
public class OzelAdaptor extends BaseAdapter {
LayoutInflater layoutInflater;
List<lt> list;
Activity activity;
ConnectionClass connectionClass;
int urunAdet=0;
public myAdaptor(Activity activity, List<lt> mList) {
layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
list = mList;
this.activity = activity;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View sView;
sView = layoutInflater.inflate(R.layout.sat, null);
ImageView iv = (ImageView) sView.findViewById(R.id.imageView);
TextView tv = (TextView) sView.findViewById(R.id.tvnm);
TextView tv2 = (TextView) sView.findViewById(R.id.tvfm);
final TextView tvadet = (TextView) sView.findViewById(R.id.texw);
final Button button = (Button) sView.findViewById(R.id.button);
final lt lst = list.get(position);
tv.setText(lt.getnm().toString());
tv2.setText(lt.getf().toString());
/ ...
myAdapter布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="110dp"
android:gravity="center_vertical"
android:layout_margin="5dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:scaleType="fitXY"
/>
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="-33dp"
android:layout_marginLeft="-70dp"
android:textColor="#ffffff"
android:gravity="center"
android:text="3"
android:background="@drawable/backg"
android:textSize="17dp"
android:textStyle="bold"
android:layout_centerHorizontal="true" />
<LinearLayout
android:layout_weight="1.13"
android:layout_width="0dp"
android:layout_height="90dp"
android:layout_marginLeft="50dp"
android:orientation="vertical">
<TextView
android:id="@+id/tvnm"
android:layout_width="wrap_content"
android:textSize="26dp"
android:layout_height="wrap_content"
android:text="Kahve"/>
<TextView
android:layout_marginTop="2dp"
android:id="@+id/tvfm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 TL"/>
</LinearLayout>
<Button
android:id="@+id/button"
android:background="@drawable/click"
android:layout_marginRight="1dp"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginTop="0dp"/>
</LinearLayout>
我保存的项目:
重新加载(返回项目):
问题: