gpt4 book ai didi

安卓处理器

转载 作者:行者123 更新时间:2023-11-29 01:13:20 25 4
gpt4 key购买 nike

我正在使用 AlertDialog 显示文件中的图像,但是当我按下按钮显示对话框时,应用停止卡住 6 秒,然后显示警报对话框。

我的代码:

listView_prev.setOnItemClickListener(new AdapterView.OnItemClickListener() {


@Override
public void onItemClick(AdapterView<?> arg0, final View arg1, int arg2, long arg3) {
//listview click event handling
TextView id = (TextView) arg1.findViewById(R.id.textView17);
final int id_To_Search = Integer.valueOf(id.getText().toString());
Cursor item=mydb.singlecons(id_To_Search);
Cursor att=mydb.attrs(id_To_Search);
Cursor picloc=mydb.singleconspic(id_To_Search);
att.moveToFirst();
List<String> list = new ArrayList<>();
// Log.d("temp",att.getColumnName(1));

while (!att.isAfterLast())
{
int l=att.getColumnCount();
Log.d("length", String.valueOf(l));
for(int i=2;i<l;i++){
Log.d("for","for");
if(att.getString(i)!=null){
String b= att.getColumnName(i)+" "+att.getString(i);
list.add(b);
Log.d("att",b);
}
}
Log.d("while","while");
att.moveToNext();
}
att.close();
Log.d("list", String.valueOf(list));
picloc.moveToFirst();

FilePathStrings = new String[picloc.getCount()];
int i=0;
while (!picloc.isAfterLast()){
Log.d("picloc",picloc.getString(2));
FilePathStrings[i]=picloc.getString(2);
i++;
picloc.moveToNext();
}

item.moveToFirst();

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(Consultation.this);
LayoutInflater inflater = getLayoutInflater();
View dialogView = inflater.inflate(R.layout.alert_label_editor, null);
dialogBuilder.setView(dialogView);

TextView con=(TextView)dialogView.findViewById(R.id.textView29);
con.setText("Consultation on "+item.getString(4));
TextView des=(TextView)dialogView.findViewById(R.id.textView28);
des.setText(item.getString(2));
TextView pre=(TextView)dialogView.findViewById(R.id.textView31);
pre.setText(item.getString(3));
TextView fee=(TextView)dialogView.findViewById(R.id.textView32);
fee.setText(item.getString(5));
adapter1 = new GridViewAdapter(FilePathStrings,getApplicationContext());
grid = (GridView) dialogView.findViewById(R.id.gridview);
grid.setAdapter(adapter1);
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + FilePathStrings[position]), "image/*");
startActivity(intent);
}

});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();

Gridviewadapter.java

class GridViewAdapter extends BaseAdapter {

private String[] filepath;
private static LayoutInflater inflater = null;
GridViewAdapter(String[] fpath,Context context) {
filepath = fpath;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}
public int getCount() {
return filepath.length;

}

public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}

public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.gridview_item, null);
ImageView image = (ImageView) vi.findViewById(R.id.image);
Bitmap bmp = BitmapFactory.decodeFile(filepath[position]);

Bitmap thumbBitmap = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(filepath[position]),320,240);

image.setImageBitmap(thumbBitmap);

return vi;
}
}

我该如何解决这个问题?我知道 handler 会在这里提供帮助,有人可以帮我解决这个问题吗?

最佳答案

I want the app to freeze for 6 seconds and then show the alert dialog

onItemClick 方法上,通过调用 singlecons,attrs,singleconspic 方法执行 3-4 次数据库操作,并从 Cursor 的 读取数据。这将在不执行任何操作的情况下显示 UI 线程。

建议是,使用 AsyncTask 而不是 Handler用于调用所有 DB 方法并从 Cursor 获取数据。

在将数据返回到 onPostExecute 之前等待 6 秒 doInBackground

关于安卓处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41482703/

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