我为我的列表视图创建了一个自定义数组适配器,但是由于某种原因,数据没有显示在列表视图项中。当我将log语句放入扩展ArrayAdapter的自定义适配器的getView方法中时,甚至连日志猫也什么都不显示。 这是持有列表视图的活动
public class booktable extends AppCompatActivity {
ListView mylv;
int[] array = new int[5];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_booktable);
mylv = findViewById(R.id.mylv);
array = new int[]{1, 0, 0, 0, 1};
ListAdapter la = new customadapter(getApplicationContext(),R.layout.activity_booktable,array);
mylv.setAdapter(la);
}
}
这是我的自定义适配器
public class customadapter extends ArrayAdapter {
LayoutInflater li;
int[] table = new int[5];
public customadapter(@NonNull Context context,int resource, int [] array) {
super(context,resource);
li = LayoutInflater.from(context);
table = array;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View v = li.inflate(R.layout.custom_row,parent);
ImageView img = v.findViewById(R.id.img);
TextView tv = v.findViewById(R.id.tv);
if(table[position]==0)
{
tv.setText("FULL");
tv.setTextColor(Color.RED);
}
if(table[position]==1)
{
tv.setText("AVAILABLE");
tv.setTextColor(Color.GREEN);
}
return v;
}
}
答案 0 :(得分:0)
尝试将参数数组或集合传递给ArrayAdapter构造函数,如下所示:
<?php
include '../include/connect.php';
$id =(int)$_GET['id'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file_img" />
<input type="hidden" name="id" value="<?php echo $id;?>" />
<input type="submit" name="btn_upload" value="Upload">
</form>
<?php
if(isset($_POST['btn_upload']))
{
$filetmp = $_FILES["file_img"]["tmp_name"];
$filename = $_FILES["file_img"]["name"];
$filetype = $_FILES["file_img"]["type"];
$filepath = "photo/".$filename;
$id = $_POST['id'];
move_uploaded_file($filetmp,$filepath);
$sql = "INSERT INTO upload_img (img_name,img_path,img_type,im_id) VALUES ('$filename','$filepath','$filetype','.$id.')";
mysqli_query($con, $sql);
}
?>
</body>
</html>