gpt4 book ai didi

java - 如果包含其他数据则显示列表 AlertDialog

转载 作者:行者123 更新时间:2023-11-29 05:31:43 25 4
gpt4 key购买 nike

  1. LoginActivity 中显示单个按钮
  2. 并且想要启动 UploadActivity,如果UploadActivity 的列表包含任何其他数据,则显示警告“在 UploadActivity 中找不到图像”

简而言之,如果上传 Activity 在列表中没有数据,我只想显示警报对话框,否则启动 UploadActivity...

btnCheckUpload.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub


AlertDialog.Builder alertdialog = new AlertDialog.Builder(LoginActivity.this);
alertdialog.setTitle(getResources().getString(R.string.app_name));
alertdialog.setMessage("No Images found in UploadActivity");
alertdialog.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alertdialog.show();
}
}
});

UploadActivity.java:-

    public class UploadActivity extends Activity  {

final private static int DIALOG_LOGIN = 1;
EditText editPersonName, editPersonaEmail, editPersonTelephone, parental_email ;
TextView editImageName ;
String fileName;

static ListView lstView;
private Handler handler = new Handler();;

static List <String> ImageList;
String strPath;

CheckBox chkOption3;

TextView tv1, tv2;
CheckBox chkOption1, chkOption2 ;

int position ;

static File f1;

static String folder = null ;

Intent i;
Intent intent ;

TextView textHeading1;

static File[] files;
static File file ;

static List <String> it ;

static String textHeading = null;
// new Class DB
final myDBClasss myDb = new myDBClasss(this);

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_upload);

textHeading1 = (TextView) findViewById(R.id.txtEventNameDate1);
textHeading1.setText(CameraLauncherActivity.folder);


/*** Get Images from SDCard ***/
ImageList = getSD();

// ListView and imageAdapter
lstView = (ListView) findViewById(R.id.listView1);
lstView.setAdapter(new ImageAdapter(this));
}


public static List <String> getSD()
{
it = new ArrayList <String>();
String string = "/mnt/sdcard/Pictures/Awesome/";
f1 = new File (string+ CameraLauncherActivity.folder+ "/");
files = f1.listFiles ();

for (int i = 0; i < files.length; i++)
{
file = files[i];
Log.d("Count",file.getPath());
it.add (file.getPath());
}
return it;
}


public class ImageAdapter extends BaseAdapter
{
private Context context;

public ImageAdapter(Context c)
{
// TODO Auto-generated method stub
context = c;
}

public int getCount() {
// TODO Auto-generated method stub
return ImageList.size();
}

public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}

public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub

LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

if (convertView == null) {
convertView = inflater.inflate(R.layout.list_upload, null);
}

// ColImgName
TextView txtName = (TextView) convertView.findViewById(R.id.ColImgName);
strPath = ImageList.get(position).toString();

// Get File Name
fileName = strPath.substring( strPath.lastIndexOf('/')+1, strPath.length() );
file = new File(strPath);
@SuppressWarnings("unused")
long length = file.length();
txtName.setText(fileName);

// Image Resource
ImageView imageView = (ImageView) convertView.findViewById(R.id.ColImgPath);
final BitmapFactory.Options options = new BitmapFactory.Options();

options.inSampleSize = 8;

Bitmap bm = BitmapFactory.decodeFile(strPath,options);
imageView.setImageBitmap(bm);


// ColStatus
final ImageView txtStatus = (ImageView) convertView.findViewById(R.id.ColStatus);
txtStatus.setImageResource(R.drawable.bullet_button);

// progressBar
final ProgressBar progress = (ProgressBar) convertView.findViewById(R.id.progressBar);
progress.setVisibility(View.GONE);

//btnUpload
final ImageButton btnUpload = (ImageButton) convertView.findViewById(R.id.btnUpload);
btnUpload.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Upload
btnUpload.setEnabled(false);

startUpload(position);
}
});


return convertView;

}
}

最佳答案

lstView.getChildCount() 将返回组中 child 的数量。这是您查看的。因此存储您的 ImageAdapter 的引用然后使用 adapter.getcount();

您还可以检查您的 ImageList 大小。

代替

if (UploadActivity.lstView.getChildCount() > 0)

使用

if (imageList.size) > 0)

或者if (adapter.getcount() > 0)

关于java - 如果包含其他数据则显示列表 AlertDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20854803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com