伊夫看着这个问题上计算器的几个其他问题,但是我现在无法落实到我的代码这是我做的事情有点不同,我相信。我仍然在学习Android Studio,因此请耐心等待任何愚蠢。Android Studio中的ListView复选框保存
我期待在列表视图右侧创建复选框我目前有检查将留在该国,当用户加载应用早在
XML:
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Which Will Be Next"
android:textAllCaps="false"
android:textColor="#f1b75a"
android:textSize="32sp"
android:textStyle="bold" />
<ListView
android:id="@+id/results_listview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@+id/textView3"></ListView>
</RelativeLayout>
活动代码:
public class .... extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_flavour);
ListView resultListView = (ListView) findViewById(R.id.results_listview);
HashMap<String, String> nameAddress = new HashMap<>();
nameAddress.put("exmp ", "Locate");
List<HashMap<String, String>> listItems = new ArrayList<>();
SimpleAdapter adapter = new SimpleAdapter(this, listItems, R.layout.list_item, new String[]{"First Address", "Second Address"},new int[]{R.id.tv1, R.id.tv3});
Iterator it = nameAddress.entrySet().iterator();
while (it.hasNext()){
HashMap<String, String> resultsMap = new HashMap<>();
Map.Entry pair = (Map.Entry)it.next();
resultsMap.put("First Address", pair.getKey().toString());
resultsMap.put("Second Address", pair.getValue().toString());
listItems.add(resultsMap);
}
resultListView.setAdapter(adapter);
}
}
列表Items.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckedTextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffa200"
android:textSize="21sp"
android:textStyle="bold"
android:drawableLeft="?android:attr/listChoiceIndicatorMultiple"
/>
<CheckedTextView
android:id="@+id/tv3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold"
/>
</LinearLayout>
任何帮助表示赞赏:)
因此,实际上什么ü想要做什么? –
@LokeshDesai我想一个复选框添加到列表视图中的每一项,如果他们点击它的状态被保存为下一次登录时 – 77rshah
简单的只是使用份额偏好研究用于存储选择复选框的状态 –