我是一个新的 android 开发人员并且我创建了求职应用程序,我需要在其中显示所有带有爱和喜欢的图像选项的工作,以及保存在我的数据库中的爱和喜欢的工作,
当我点击网络服务并显示作业并检查数据库是否存在作业然后设置爱或喜欢的图像,
我的问题是只有一个图像更改但我保存/检查了许多工作请帮助我如何处理列表视图中的图像
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;
}
}
抱歉英语不好 任何帮助表示赞赏。先感谢您。