0
정적 메서드를 사용하여 하나의 활동 클래스와 하나의 추상 클래스가 있습니다. 이 메서드에서는 jsonArray를 목록보기로 렌더링하려고합니다. 다른 클래스의 정적 메서드에서 Java android findViewById
이
은public class FeedActivity extends BaseActivity {
...
private void renderFeed(String data){
try {
JSONObject json = new JSONObject(data);
JSONArray d = json.getJSONArray("data");
RenderLists.renderFeed(d);
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
}
}
활동
입니다 그리고 여기에 정적 방법이다.abstract class RenderLists {
static void renderFeed(JSONArray data) throws JSONException{
ArrayList feedList1 = new ArrayList<HashMap<String, Object>>();
ListView feedList = (ListView) layout.findViewById(R.id.feedList); // This isn't working
for (int i = 0; i < data.length(); i++) {
HashMap<String, Object> hm;
hm = new HashMap<String, Object>();
hm.put("name", data.getJSONObject(i).getString("name").toString());
feedList1.add(hm);
FeedItemAdapter adapter = new FeedItemAdapter(FeedActivity.this, feedList1, R.layout.feed_list,
new String[] {"name"}, new int[] { R.id.feedCheckinName});
feedList.setAdapter(adapter);
feedList.setChoiceMode(feedList.CHOICE_MODE_SINGLE);
}
}
}
정적 메소드에서 Activity 및 ListView를 얻는 방법은 무엇입니까? 설명해주세요.
abstract class RenderLists {
static void renderFeed(JSONArray data, Activity act, ListView lv) throws JSONException{
...
}
}
는 그렇다하더라도 view
가 UI 스레드에서 제외하고 업데이트 할 수 없습니다 기억 : 런타임에이를 전달
예, 방금 배웠습니다!) –
다음 stackoverflow 나쁜 장소입니다 ... https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html – Selvin
왜 그것을 필요합니까? – drulabs