我在列表视图中添加 2 个数字时遇到问题。这是我的行,有 2 个文本视图(每个数字)。textView2 忽略
<?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="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" - "
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
当用户添加号码时,它将显示在列表视图中。第二个数字必须是 11 - 用户插入的那个数字。一切正常,但我不知道如何显示第二个数字。
public class MainActivity extends Activity {
ArrayAdapter<String> m_adapter;
ArrayList<String> m_listItems = new ArrayList<String>();
Button bt;
EditText et;
TextView tv;
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Inflate the menu; this adds items to the action bar if it is present.
bt = (Button) findViewById(R.id.button1);
et = (EditText) findViewById(R.id.editText1);
tv = (TextView) findViewById(R.id.textView1);
lv = (ListView) findViewById(R.id.lista);
m_adapter = new ArrayAdapter<String>(this,R.layout.row, R.id.textView1);
lv.setAdapter(m_adapter);
//final String input = et.getText().toString();
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String input = et.getText().toString();
if(null!=input&&input.length()>0){
String maxpunti = "11";
int a = Integer.parseInt(maxpunti);
int b = Integer.parseInt(input);
int c = a-b;
String input2 = String.valueOf(c);
m_adapter.add(input);
m_adapter.add(input2);
m_adapter.notifyDataSetChanged();
}
}
});
}
}