我是一名新的Android开发人员而且我已经创建了求职应用程序,我需要用爱显示所有工作,并且喜欢图像选项,以及爱和喜欢的工作保存在我的数据库中,
当我点击Web服务并显示作业并检查数据库是否存在工作然后设置爱情或喜欢图像,
我的问题是只有一个图像更改,但我保存/检查了许多作业 Plz帮助我如何在列表视图中处理图像
public View getView(int position, View convertView, ViewGroup parent) {
final String description;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View row =mInflater.inflate(R.layout.list_item, parent,false);
txtcompany = (TextView) row.findViewById(R.id.txt_company);
imageView = (ImageView) row.findViewById(R.id.img);
txtPosition= (TextView) row.findViewById(R.id.txt_position);
txtCity= (TextView) row.findViewById(R.id.txt_city);
txtState= (TextView) row.findViewById(R.id.txt_state);
txtcompany.setText("Company: "+companyarray[position]);
txtPosition.setText("Position: "+positonarray[position]);
txtCity.setText("City: "+cityarray[position]);
txtState.setText("State: "+statearray[position]);
imageView.setTag(receiceValueOfAdapter.get(position));
description= Descarray[position];
try{
//imageView.setBackgroundResource(R.drawable.starapplied);
DBAdapter db = DBAdapter.getInstance(getApplicationContext());
db.openWritableDatabase();
savedItems=db.getAllData(str_user);
if(savedItems.get(0).getid().equals(receiceValueOfAdapter.get(position)))
{
imageView.setBackgroundResource(R.drawable.starsave);
}
}catch(Exception e)
{
// Toast.makeText(getApplicationContext(), ""+e, Toast.LENGTH_LONG).show();
}
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
preferences=getSharedPreferences("LoginActivity", MODE_PRIVATE);
str_user=preferences.getString("USERNAME", "DEFAULT");
if(str_user !=null && !str_user.equals("DEFAULT"))
{
try{
AlertDialog.Builder builder = new AlertDialog.Builder(Job_Description.this);
builder.setTitle("Save this Job ?");
// builder.setMessage("whould You like to save job");
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// startActivity(new Intent(Job_Description.this,JobSearch.class));
v.setBackgroundResource(R.drawable.starsave);
Toast.makeText(getApplicationContext(), ""+v.getTag(), Toast.LENGTH_LONG).show();
DBAdapter db = DBAdapter.getInstance(getApplicationContext());
db.openWritableDatabase();
Toast.makeText(getApplicationContext(), "Status///"+db.getStatus(""+v.getTag(),str_user), Toast.LENGTH_LONG).show();
if(!db.getStatus(""+v.getTag(),str_user))
{
Toast.makeText(getApplicationContext(), "Inserted", Toast.LENGTH_LONG).show();
db.insertlocation(v.getTag().toString(),
txtPosition.getText().toString(),
txtCity.getText().toString(),
txtState.getText().toString(),
txtcompany.getText().toString(),
description,
""+0,
str_user,
str_pass);
}
else
{
db.DeleteLocation(v.getTag().toString());
Toast.makeText(getApplicationContext(), "Already In Database", Toast.LENGTH_LONG).show();
}
// Log.e("info", "OK");
}
});
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
dialog.cancel();
}
});
builder.show();
}catch(Exception e)
{
Log.d("Image click", e.toString());
}
}
else
{
try
{
AlertDialog.Builder builder = new AlertDialog.Builder(Job_Description.this);
builder.setTitle("Get You Job Search Started !");
// builder.setMessage("whould You like to save job");
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(Job_Description.this,LoginActivity.class));
finish();
// Log.e("info", "OK");
}
});
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
dialog.cancel();
}
});
builder.show();
} catch(Exception e)
{
Log.d("Image click", e.toString());
}
}
}
});
return row;
}
}
对不起英语不好任何帮助表示赞赏。提前谢谢。
答案 0 :(得分:0)
您在循环中获取数据库值,只获取一个值