BaseAdapter를 사용하여 ListView에 이미지를 표시하려면 다음 코드를 사용하고 있습니다. 코드는 드로어 블 폴더 내부의 이미지를 표시합니다. BaseAdapter를 사용하여 ListView에서 원격 이미지를 표시하는 방법은 무엇입니까?
String flags[] ={"http://www.website.com/images/usa.png","http://www.website.com/images/china.png","http://www.website.com/images/australia.png","http://www.website.com/images/portugle.png","http://www.website.com/images/norway.png","http://www.website.com/images/new_zealand.png"};
전문가가 사전에 change.Thanks 할 필요가 어떤 부분이 저를 보여줄 수 : 그것은 다음과 같은 배열에서 원격 이미지를 표시하므로하지만 코드를 수정합니다.
MainActivity.java :
public class MainActivity extends Activity {
ListView simpleList;
String countryList[] = {"USA", "China", "australia", "Portugle", "Norway", "NewZealand"};
int flags[] = {R.drawable.usa, R.drawable.china, R.drawable.australia, R.drawable.portugle, R.drawable.norway, R.drawable.new_zealand};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
simpleList = (ListView) findViewById(R.id.simpleListView);
CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), countryList, flags);
simpleList.setAdapter(customAdapter);
simpleList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), "Hello " + countryList[position], Toast.LENGTH_LONG).show();
}
});
}
}
CustomAdapter.java : 당신은 할 필요가
Public class CustomAdapter extends BaseAdapter {
Context context;
String countryList[];
int flags[];
LayoutInflater inflter;
public CustomAdapter(Context applicationContext, String[] countryList, int[] flags) {
this.context = context;
this.countryList = countryList;
this.flags = flags;
inflter = (LayoutInflater.from(applicationContext));
}
@Override
public int getCount() {
return countryList.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflter.inflate(R.layout.activity_listview, null);
TextView country = (TextView) view.findViewById(R.id.textView);
ImageView icon = (ImageView) view.findViewById(R.id.icon);
country.setText(countryList[i]);
icon.setImageResource(flags[i]);
return view;
}
}
감사합니다. 나는 안드로이드 개발 경험이별로 없기 때문에 함수를 작성하고 getView 내부에서 호출하여 이미지 배열을 전달하여 listview에 표시하는 방법에 대한 자습서를 가르쳐 주시겠습니까? – user1788736
그렇습니다. https://www.simplifiedcoding.net/android-volley-tutorial-fetch-json/ – HaroldSer
나중에 잭슨 데이터 바인딩을 사용하여 응답의 값을 POJO (모델 클래스)에 매핑 할 수 있습니다. 참조 : https://stackoverflow.com/questions/25545984/how-to-use-jackson-objectmapper-to-parse-json-response-to-java-objects – HaroldSer