我正在创建一个跨平台的应用程序,并且无法将tableview实现到listview。
对于列表视图,我希望为每一行分配一个数字(点),当用户选择列表视图中的特定行时,它将从其total_points中减去这些点,然后禁用该按钮...这是if他们有足够的分数
^在android
中遇到麻烦我将上传Swift版本和Android版本(不完整的版本)
的iOS:
var redeem = ["120 Points", "150 Points", "200 Points", "200 Points", "300 Points", "400 Points", "600 Points"]
var points = [120,150,200,200,300,400,600]
var myIndex = 0
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return(redeem.count)
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
cell.textLabel?.text = redeem[indexPath.row]
return(cell)
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
if Total_Points >= points[indexPath.row]
{
myIndex = indexPath.row
Total_Points -= points[indexPath.row]
pointsLabel.text = "Total Points: \(Total_Points)"
let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbPopUpID") as! PopUpViewController
self.present(popOverVC, animated: true, completion: nil)
save.setValue(Total_Points, forKey: "Total Points")
}
}
机器人:
listView = (ListView)findViewById(R.id.list);
//define and show in ListView
String[] redeem = new String[]{
"120 Points",
"150 Points",
"200 Points",
"200 Points",
"300 Points",
"400 Points",
"600 Points"
};
//define a new adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, redeem);
//assign to listview
listView.setAdapter(adapter);
//click listener
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ListView Clicked item index
int itemPosition = position;
// ListView Clicked item value
String itemValue = (String) listView.getItemAtPosition(position);
// do something
}
});