2015-01-09 5 views
0

내 문제는 실제로 간단하지만 코드가 잘못되거나 내가 올바르게 구현하고 있는지 파악할 수 없습니다. volley를 사용하여 내 listview를로드합니다. 세부 정보 활동, 활동 중지로 이동하기 위해 항목을 클릭하십시오. 매니페스트에 세부 활동을 등록 했으므로 로그캣을 업로드 할 것입니다. 내가 잘못 알아 낸 걸 도와주세요. 고마워.내 목록보기에서 예외가 발생하는 OnItemClickListener

FrontPage.java :

public class Frontpage extends ActionBarActivity{ 
 
\t private String TAG = this.getClass().getSimpleName(); 
 
\t private static String Title="title"; 
 
\t private static String Desc="desc"; 
 
\t private static String Date ="pubDate"; 
 
\t 
 
\t private ListView lstView; 
 
    private RequestQueue mRequestQueue; 
 
    private ArrayList<NewsModel> arrNews ; 
 
    private LayoutInflater lf; 
 
    private VolleyAdapter va; 
 
    private ProgressBar pDialog; 
 

 
    @Override 
 
    protected void onCreate(Bundle savedInstanceState) { 
 
    super.onCreate(savedInstanceState); 
 
    setContentView(R.layout.trending); 
 
     
 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
 

 
    Intent newActivity4=new Intent(); 
 
    setResult(RESULT_OK, newActivity4); 
 
     
 
     
 
    lf = LayoutInflater.from(this); 
 

 

 
    arrNews = new ArrayList<NewsModel>(); 
 
    va = new VolleyAdapter(); 
 

 
    lstView = (ListView) findViewById(R.id.listView); 
 
    lstView.setAdapter(va); 
 
    mRequestQueue = Volley.newRequestQueue(this); 
 
    String url = "http://snapt.t15.org/news.js"; 
 
    pDialog =(ProgressBar)this.findViewById(R.id.progressBar); 
 
     // Showing progress dialog before making http request 
 
    pDialog.setVisibility(View.VISIBLE); 
 
    try{ 
 
      
 
    }catch(Exception e) 
 
    { 
 

 
    } 
 
    JsonObjectRequest jr = new JsonObjectRequest 
 
    \t (Request.Method.GET,url,null,new Response.Listener<JSONObject>() { 
 
    @Override 
 
    public void onResponse(JSONObject response) { 
 
    Log.i(TAG,response.toString()); 
 
    parseJSON(response); 
 
    va.notifyDataSetChanged(); 
 
    pDialog.setVisibility(View.GONE); 
 
;   } 
 
    },new Response.ErrorListener() { 
 
    @Override 
 
    public void onErrorResponse(VolleyError error) { 
 
    if (error instanceof NoConnectionError){ 
 
Toast.makeText(getBaseContext(), "Bummer..There's No Internet connection!", Toast.LENGTH_LONG).show(); 
 

 
}}; 
 
}); 
 
mRequestQueue.add(jr); 
 

 
} 
 
    
 
    
 
private void parseJSON(JSONObject json){ 
 
    try{ 
 
    JSONObject value = json.getJSONObject("value"); 
 
    JSONArray items = value.getJSONArray("items"); 
 
    for(int i=0;i<items.length();i++){ 
 

 
JSONObject item = items.getJSONObject(i); 
 
    NewsModel nm = new NewsModel(); 
 
    nm.setTitle(item.optString("title")); 
 
    nm.setDescription(item.optString("description")); 
 
    nm.setLink(item.optString("link")); 
 
    nm.setPubDate(item.optString("pubDate")); 
 
    arrNews.add(nm); 
 
}} 
 

 
catch(Exception e){ 
 
e.printStackTrace(); 
 
    } 
 

 
    
 
lstView.setOnItemClickListener(new AdapterView.OnItemClickListener(){ 
 

 
@Override 
 
    public void onItemClick(AdapterView<?> parent, View view, 
 
    int position, long id) { 
 
    String name = ((TextView) view.findViewById(R.id.title)) 
 
.getText().toString(); 
 
    String desc = ((TextView) view.findViewById(R.id.description)) 
 
\t .getText().toString(); 
 
    \t \t 
 
    Intent i = new Intent(Frontpage.this, Detail.class); 
 
    i.putExtra(Title, name); 
 
    i.putExtra(Desc, desc); 
 
    \t \t 
 
    startActivity(i); 
 
    } 
 
});} 
 
class NewsModel{ 
 
private String title; 
 
    private String link; 
 
    private String description; 
 
    private String pubDate; 
 

 
    void setTitle(String title) { 
 
this.title = title; 
 
    } 
 

 
    void setLink(String link) { 
 
this.link = link; 
 
    } 
 

 
void setDescription(String description) { 
 
    this.description = description; 
 
    } 
 

 
void setPubDate(String pubDate) { 
 
    this.pubDate = pubDate; 
 
    } 
 

 
String getLink() { 
 
    return link; 
 
     } 
 

 
String getDescription() { 
 
    return description; 
 
     } 
 

 
    String getPubDate() { 
 
    return pubDate; 
 
    } 
 

 
    String getTitle() { 
 

 
return title; 
 
     } 
 
    } 
 

 

 
class VolleyAdapter extends BaseAdapter{ 
 

 
@Override 
 
    public int getCount() { 
 
    return arrNews.size(); 
 
    } 
 
@Override 
 
    public Object getItem(int i) { 
 
    return arrNews.get(i); 
 
} 
 

 
@Override 
 
    public long getItemId(int i) { 
 
     return 0; 
 
     } 
 

 
@Override 
 
    public View getView(int i, View view, ViewGroup viewGroup) { 
 
    ViewHolder vh ; 
 
    if(view == null){ 
 
    vh = new ViewHolder(); 
 
    view = lf.inflate(R.layout.row_listview,null); 
 
    vh.tvTitle = (TextView) view.findViewById(R.id.txtTitle); 
 
    vh.tvDesc = (TextView) view.findViewById(R.id.txtDesc); 
 
    vh.tvDate = (TextView) view.findViewById(R.id.txtDate); 
 
    view.setTag(vh); 
 
    } 
 
else{ 
 
    vh = (ViewHolder) view.getTag(); 
 
    } 
 

 
    NewsModel nm = arrNews.get(i); 
 
    vh.tvTitle.setText(nm.getTitle()); 
 
    vh.tvDesc.setText(nm.getDescription()); 
 
    vh.tvDate.setText(nm.getPubDate()); 
 
    return view; 
 
    } 
 

 
    class ViewHolder{ 
 
    TextView tvTitle 
 
    TextView tvDesc; 
 
    TextView tvDate; 
 

 
} 
 
} 
 
}

DetailsActivity.java :

public class NewsDetails extends ActionBarActivity{ 
private static String Title="title"; 
private static String Desc="desc"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.newsdetail); 
getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
Intent i=getIntent(); 
String name = i.getStringExtra(Title); 
String desc = i.getStringExtra(Desc); 

TextView lblName = (TextView) findViewById(R.id.name_label); 
TextView lblDesc = (TextView) findViewById(R.id.txtDesc); 
lblName.setText(name); 
lblDesc.setText(desc); 
}} 

로그 캣 :

01-09 15:42:04.031: E/dalvikvm(19341): GC_CONCURRENT freed 437K, 30% free 9679K/13763K, paused 4ms+17ms, total 73ms 
01-09 15:42:04.161: I/Frontpage(19341): {"value":{"callback":"","generator":"http:\/\/pipes.yahooapis.com\/pipes\/","pubDate":"Fri, 09 Jan 2015 10:15:08 +0000","title":"Cycling News","items":[{"guid":{"content":"urn:newsml:sports.yahoo,lego:19780928:top,article,fe3b6341-a4cf-3812-84e7-bf05a6fcc813-l:1","isPermaLink":"false"},"pubDate":"Thu, 08 Jan 2015 04:47:55 PST","category":"SC","title":"ROOM BOOKING TO BEGIN ON WEDNESDAY 7TH","y:title":"Former Tour winner Wiggins launches his own cycling team (The Associated Press)","y:id":{"value":"urn:newsml:sports.yahoo,lego:19780928:top,article,fe3b6341-a4cf-3812-84e7-bf05a6fcc813-l:1","permalink":"false"},"description":"Hostel booking by Incoming Students has been rescheduled to WEDNESDAY 7TH JANUARY 2015 as from 2.30pm.This is a change from the prior Information indicated; with the Dates of 4th ? 6th (the same time that re-booking by continuing students was to be between 24th Dec ? 4th January 2015).As explained by the ICT Officer (In charge of the Hostels Management System), Mr. Masibo, the changes, are as a result of the following:\n? Slow Rate of Re-booking by the Continuing Students (Majorly the 1st years). Some of whom had forgotten their passwords and needed their accounts to be rest.\n? By Yesterday?s deadline, less than half of such students had Rebooked (retained) their rooms thus posing a challenge in opening the system for the incoming groups. Thus between now, they are urged to hasten their process of re-booking. ","link":"http:\/\/us.rd.yahoo.com\/sports\/rss\/sc\/SIG=139h7572n\/*http%3A\/\/sports.yahoo.com\/news\/former-tour-winner-wiggins-launches-own-cycling-team-124755795--spt.html","y:published":{"minute":"47","day_of_week":"4","utime":"1420721275","timezone":"UTC","day_name":"Thursday","second":"55","day_ordinal_suffix":"th","month":"1","year":"2015","month_name":"January","day":"8","hour":"12"},"y:repeatcount":"1"},{"guid":{"content":"urn:newsml:sports.yahoo,lego:19780928:top,article,c9aeb898-8485-36f9-8171-08179126c1cd-l:1","isPermaLink":"false"},"pubDate":"Thu, 08 Jan 2015 04:07:47 PST","media:content":{"type":"image\/jpeg","url":"http:\/\/l.yimg.com\/iu\/api\/res\/1.2\/yeyi9ZW1Brm77oKQ5YwDkw--\/YXBwaWQ9eXZpZGVvO2NoPTI4Njtjcj0xO2N3PTI4NjtkeD04MztkeT0xO2ZpPXVsY3JvcDtoPTEzMDtxPTEwMDt3PTEzMA--\/http:\/\/media.zenfs.com\/en_us\/News\/Reuters\/2015-01-08T120747Z_1_LYNXMPEB070GQ_RTROPTP_2_SPORT-GAMES.JPG","width":"130","height":"130"},"category":"SC","title":"Former Tour champion Wiggins to launch own team (Reuters)","y:title":"Former Tour champion Wiggins to launch own team (Reuters)","y:id":{"value":"urn:newsml:sports.yahoo,lego:19780928:top,article,c9aeb898-8485-36f9-8171-08179126c1cd-l:1","permalink":"false"},"description":"<p><a rel=\"nofollow\" target=\"_blank\" href=\"http:\/\/us.rd.yahoo.com\/sports\/rss\/sc\/SIG=1317e54jm\/*http%3A\/\/sports.yahoo.com\/news\/former-tour-champion-wiggins-launch-own-team-120747028--spt.html\"><img src=\"http:\/\/l.yimg.com\/iu\/api\/res\/1.2\/yeyi9ZW1Brm77oKQ5YwDkw--\/YXBwaWQ9eXZpZGVvO2NoPTI4Njtjcj0xO2N3PTI4NjtkeD04MztkeT0xO2ZpPXVsY3JvcDtoPTEzMDtxPTEwMDt3PTEzMA--\/http:\/\/media.zenfs.com\/en_us\/News\/Reuters\/2015-01-08T120747Z_1_LYNXMPEB070GQ_RTROPTP_2_SPORT-GAMES.JPG\" width=\"130\" height=\"130\" alt=\"England's Bradley Wiggins (R) leads his team to a silver medal in men's 4000m team pursuit finals at the 2014 Commonwealth Games in Glasgow, Scotland, July 24, 2014.   REUTERS\/Phil Noble\" align=\"left\" border=\"0\"><\/a><\/p><p>LONDON (Reuters) - Four-times Olympic champion and former Tour de France winner Bradley Wiggins is launching his own professional cycling team with the aim of providing more British gold in Rio. Wiggins, who will continue to ride for Team Sky until April's Paris Roubaix road classic before concentrating on his own Rio 2016 Olympic preparations, will head up the team comprising of young home-grown riders. The team, which will operate independently of British Cycling and focus on both road and track disciplines, will be called WIGGINS and will receive financial backing from Sky. ...<\/p><br 
01-09 15:42:09.011: W/dalvikvm(19341): threadid=1: thread exiting with uncaught exception (group=0x40dfa438) 
01-09 15:42:11.501: E/Trace(23337): error opening trace file: No such file or directory (2) 
01-09 15:42:11.541: W/dalvikvm(23337): Refusing to reopen boot DEX '/system/framework/hwframework.jar' 
01-09 15:42:11.661: W/System.err(23337): Invalid int: "" 
01-09 15:42:12.101: I/Adreno200-EGL(23337): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.01.21.010_msm8625_JB_REL_2.0.3_Merge_release_AU (Merge) 
01-09 15:42:12.101: I/Adreno200-EGL(23337): Build Date: 10/26/12 Fri 
01-09 15:42:12.101: I/Adreno200-EGL(23337): Local Branch: 
01-09 15:42:12.101: I/Adreno200-EGL(23337): Remote Branch: quic/jb_rel_2.0.3 
01-09 15:42:12.101: I/Adreno200-EGL(23337): Local Patches: NONE 
01-09 15:42:12.101: I/Adreno200-EGL(23337): Reconstruct Branch: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.01.21.010 + NOTHING 

If you need more code,please ask. 
+0

예외를 게시하지 않았습니다. – Misca

답변

1

소개 e R.id.txtTitleR.id.txtDesc 행 레이아웃에 R.id.txtTitleR.id.txtDesc ID가 R.id.titleR.id.description 대신에 TextView가 포함되어 있기 때문에 행에서 TextView 값을 가져 오는 데 적합합니다.

String name = (String)((TextView) view.findViewById(R.id.title)).getText(); 
    String desc =(String)((TextView) view.findViewById(R.id.txtDesc)).getText(); 
+0

감사합니다. :) 귀하의 도움에 정말로 감사드립니다. –

관련 문제