如何显示在android的列表视图的鸣叫? [英] how to show tweets in list view in android?

查看:111
本文介绍了如何显示在android的列表视图的鸣叫?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示在android的application.i列表视图鸣叫已经使用以下code,但鸣叫没有显示..可能有人请告诉如何显示这些后,每重新加载列表视图5最新的鸣叫15分钟?我已经尝试了许多codeS,但在任何结果并没有达到!

 公共类TweetsListActivity延伸活动{        TextView的电视;
        LV的ListView;
        叽叽喳喳叽叽喳喳;
        TextView的用户名;
        TweetsListAdapter适配器;
        ArrayList的<&分享Tweet GT; tweetsDataList;
        串tweetsData;        静态ConfigurationBuilder CB;
        私人静态共享preferences mShared preferences;
        AlertDialogManager警报=新AlertDialogManager();
        私有静态最后弦乐CONSUMER_KEY =;
        私有静态最后弦乐CONSUMER_SECRET =;        @覆盖
        保护无效的onCreate(捆绑savedInstanceState){
            的setContentView(R.layout.tweets_list);
            super.onCreate(savedInstanceState);
            如果(android.os.Build.VERSION.SDK_INT> 9){
                。StrictMode.ThreadPolicy政策=新StrictMode.ThreadPolicy.Builder()permitAll()建();
                StrictMode.setThreadPolicy(政策);
            }
            电视=(的TextView)findViewById(R.id.textView1);
            用户名=(的TextView)findViewById(R.id.username);
            LV =(ListView控件)findViewById(R.id.listView);
            tweetsDataList =新的ArrayList<&分享Tweet GT;();
          字符串responseBody = NULL;

尝试{

  ConfigurationBuilder建设者=新ConfigurationBuilder(); builder.setOAuthConsumerKey(CONSUMER_KEY); builder.setOAuthConsumerSecret(CONSUMER_SECRET);
URI网站=新的URI(https://api.twitter.com/1/statuses/user_timeline/.json);
 HttpClient的HC =新DefaultHttpClient();
  HTTPGET GET =新HTTPGET();
get.setURI(网站);
HTT presponse RP = hc.execute(获取);
HttpEntity实体= rp.getEntity();
 responseBody = EntityUtils.toString(实体);如果(((org.apache.http.Htt presponse)RP).getStatusLine()的getStatus code()== HttpStatus.SC_OK){
     返回的字符串= NULL;
     JSONObject的JSON =新的JSONObject(返回);
    JSONArray JA = NULL;
     JA = json.getJSONArray(结果);
    为(中间体I1 = 0; I1&下; ja.length(5); I1 ++){
    JSONObject的tweet_obj = ja.getJSONObject(I1);
    鸣叫tweetsData =新的tweet();
    字符串username = tweet_obj.getString(FROM_USER);
    字符串消息= tweet_obj.getString(文字); tweetsDataList.add(tweetsData);
                    }
                }
            }
            赶上(例外五){
 Log.e(TwitterFeedActivity,错误加载JSON,E);
            }
 适配器=新TweetsListAdapter(TweetsListActivity.this,tweetsDataList);
lv.setAdapter(适配器);
  mShared preferences = getApplicationContext()getShared preferences(我的preF,0);
        }
    }
   }
      但没有列表显示..无论是logcat的显示任何错误..
    我已经使用适配器类。这里是链接http://pastebin.com/XBErcu9c


解决方案

 鉴于ü没有设置textview.So,不妨此帮助您
@覆盖
公共查看getView(INT位置,查看convertView,父母的ViewGroup){
查看查看= convertView;
持有人持有人=新的持有人();如果(查看== NULL){
LayoutInflater VI =(LayoutInflater)this.getContext()getSystemService(Context.LAYOUT_INFLATER_SERVICE)。
鉴于= vi.inflate(R.layout.tweet_item,NULL);
}唧啾= tweets.get(位置);
如果(鸣叫!= NULL){
holder.username =(TextView中)view.findViewById(R.id.listItem);
holder.message =(TextView中)view.findViewById(R.id.message);如果(用户名!= NULL){
username.setText(tweet.username);
}如果(消息!= NULL){
message.setText(tweet.message);
}}
view.setTag(保持器);
返回视图。
}
}类持有人{
TextView的用户名;
TextView的消息;
}

i want to show tweets in a list view in android application.i have used following code but the tweets are not showing.. could anybody please tell how to show 5 latest tweets in list view which are reloaded after every 15 minutes? i have tried many codes but did not reached at any result!

 public class TweetsListActivity extends Activity {

        TextView tv;
        ListView lv;
        Twitter twitter;
        TextView username;
        TweetsListAdapter adapter;
        ArrayList<Tweet> tweetsDataList;
        String tweetsData;

        static ConfigurationBuilder cb;
        private static SharedPreferences mSharedPreferences;
        AlertDialogManager alert = new AlertDialogManager();
        private static final String CONSUMER_KEY = "";
        private static final String CONSUMER_SECRET = "";

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            setContentView(R.layout.tweets_list);
            super.onCreate(savedInstanceState);
            if (android.os.Build.VERSION.SDK_INT > 9) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy(policy);
            }
            tv = (TextView) findViewById(R.id.textView1);
            username =(TextView)findViewById(R.id.username);
            lv = (ListView) findViewById(R.id.listView);
            tweetsDataList = new ArrayList<Tweet>();
          String responseBody = null;

try {

  ConfigurationBuilder builder = new ConfigurationBuilder();            builder.setOAuthConsumerKey(CONSUMER_KEY);              builder.setOAuthConsumerSecret(CONSUMER_SECRET);
URI website = new URI("https://api.twitter.com/1/statuses/user_timeline/.json");
 HttpClient hc =new DefaultHttpClient();
  HttpGet get = new HttpGet();
get.setURI(website);
HttpResponse rp =  hc.execute(get);
HttpEntity entity = rp.getEntity();
 responseBody = EntityUtils.toString(entity);

if(((org.apache.http.HttpResponse)rp).getStatusLine().getStatusCode() == HttpStatus.SC_OK){
     String returned = null;
     JSONObject json = new JSONObject(returned);
    JSONArray ja = null;
     ja = json.getJSONArray("results");
    for (int i1 = 0; i1 < ja.length(5); i1++) {
    JSONObject tweet_obj = ja.getJSONObject(i1);
    Tweet tweetsData = new Tweet();
    String username = tweet_obj.getString("from_user");
    String message = tweet_obj.getString("text");                                                               tweetsDataList.add(tweetsData);
                    }
                }
            }
            catch (Exception e) {
 Log.e("TwitterFeedActivity", "Error loading JSON", e);
            }
 adapter = new TweetsListAdapter(TweetsListActivity.this, tweetsDataList);
lv.setAdapter(adapter);
  mSharedPreferences=getApplicationContext().getSharedPreferences("MyPref",0);
        }
    } 
   }          
      but no list is showing .. neither the logcat shows any error..
    i have used adapter classes. here is the link http://pastebin.com/XBErcu9c 

解决方案

In view u haven't set the textview.So, Might this help you


@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
Holder holder=new Holder();

if (view == null) {
LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.tweet_item, null);
}

Tweet tweet = tweets.get(position);
if (tweet != null) {
holder.username = (TextView) view.findViewById(R.id.listItem);
holder.message = (TextView) view.findViewById(R.id.message);

if (username != null) {
username.setText(tweet.username);
}

if(message != null) {
message.setText(tweet.message);
}

}
view.setTag(holder);
return view;
}
}

class Holder{
TextView username;
TextView message;
}

这篇关于如何显示在android的列表视图的鸣叫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆