@SuppressWarnings({ "rawtypes" })
public void addAttendance(ArrayList<Properties> attendanceusers) {
//tl.removeView(tr);
tl.removeAllViews();
//addHeaderAttendance();
ctr=0;
for (Iterator i = attendanceusers.iterator(); i.hasNext();) {
Properties p = (Properties) i.next();
property_list.add(p);
/** Create a TableRow dynamically **/
tr = new TableRow(this);
picurl=p.getPic();
profile = new ImageView(this);
profile.setPadding(20,50,20,50);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
InputStream in = new URL(picurl).openStream();
bmp = BitmapFactory.decodeStream(in);
} catch (Exception e) {
// log error
}
return null;
}
@Override
protected void onPostExecute(Void result) {
if (bmp != null)
profile.setImageBitmap(bmp);
}
}.execute();
profile.setOnClickListener(this);
//myButton.setPadding(5, 5, 5, 5);
Ll = new LinearLayout(this);
params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 0);
Ll.setPadding(0, 0, 20, 0);
Ll.addView(profile,params);
tr.addView((View)Ll);
ctr++;
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
上記のコードは動的デザインです。そこに私は私のデータベースからWebサービスを使用して取得する私のアンドロイド画面に画像を置く画像があります。問題は画像が点滅していて、大きすぎることです。私はスレッド内でスレッドを作成しているが、それを修正する方法はまだ混乱しているので、点滅していると思う。私の非同期タスクは、画像を取得する方法です。UIが点滅し、画像ビューのサイズを動的に変更しようとすると画像が消えます
public ArrayList<Properties> attendanceUse(String result) {
ArrayList<Properties> attendanceusers = new ArrayList<Properties>();
try {
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
Properties user = new Properties();
user.setPic(json_data.getString("student_ImgUrl"));
attendanceusers.add(user);
//attendanceusers.get(index)
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return attendanceusers;
}
上記のコードは、htdocs内のphpのクエリと関連して自分のイメージを取得する方法です。 student_imgurlは私のmysqlデータベースからURLを取得するために選択したカラムです。
private void update()
{
final Handler handler = new Handler();
Timer timer = new Timer();
String splithis;
splithis=mySpinner.getSelectedItem().toString();
splited = splithis.split(" ");
course = splited[0];
room = splited[1];
sections = splited[2];
TimerTask task = new TimerTask() {
@Override
public void run() {
data = bw.getAttendanceFromDB(term, course,sections,day,room);
handler.post(new Runnable() {
public void run() {
try {
//asyntask class ito
ArrayList<Properties> attendanceusers = attendanceUse(data);
addAttendance(attendanceusers);
} catch (Exception e) {
// error, do something
}
}//run
});//handler mo
}//runmo
};//timer
timer.schedule(task, 0,1000); //timer
}
これは私の更新無効です。画像がリアルタイムで更新されるように、タイマーが設定されています。
mySpinner.setOnItemSelectedListener(新OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
data ="";
new Thread(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
update();
}
});
}
}).start();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
return;
}
});
上記のコードは私のonCreate内の私のコードである。彼らは選んだwhenver彼らはその後、もちろん部屋-セクションを選択しますここで私は、スピナー/ドロップダウンを持っています 私は、UIの点滅を止め、画像ビューのサイズを変更することをお勧めします。