在LoginActivity中显示单个按钮
并要启动UploadActivity,如果UploadActivity的列表中包含任何其他数据,则显示警报“在UploadActivity中找不到图像”
简而言之,
如果上传活动列表中没有数据,我只想显示警报对话框,否则,请启动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()
将返回该组中的子级数。即您正在查看。因此请存储您的ImageAdapter
然后使用adapter.getcount();
您还可以检查ImageList
大小。
代替if (UploadActivity.lstView.getChildCount() > 0)
采用if (imageList.size) > 0)
要么if (adapter.getcount() > 0)