在Android Studio的ListView中嵌入推文的问题

时间:2019-07-16 17:31:10

标签: java android android-studio twitter

我正在努力做到这一点,以使时间轴上的每条推文都成为列表视图中的单独项目。该代码在.java活动文件中显示零错误或警告。但是Logcat一直显示以下内容:“将不会记录JIT配置文件信息:配置文件不会退出。” (对错别字,它说的是“退出”,而不是“存在”)。无论如何,当我在应用程序中滑动到Twitter活动时,它只会显示一个空白屏幕。我的应用程序的其他所有部分均正常运行,但这一部分将无法正常运行。

我以前在互联网连接和严格模式方面遇到问题,但是我都解决了这两个问题。同样,我的应用程序的其他所有部分都运行正常,当我滑动到该部分时,它就停止工作。它甚至不会让我从中刷出。我没有找到关于此特定错误的任何其他资源。

很明显,我没有足够的代表来发布图像,因此您可以复制此链接并查看发生了什么:

enter image description here

这是我的Twitter程序的Java活动代码:

package BetaBuild.MyClimate;

import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.MotionEvent;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

import twitter4j.Status;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;

public class TwitterFeed extends AppCompatActivity {

    ListView tweetView;
    String tweetUser;
    String tweetContent;
    String totalTweet = "";

    float x1,x2,y1,y2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.twitter_feed);

        if (android.os.Build.VERSION.SDK_INT >= 15) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }

        tweetView = findViewById(R.id.tweetView);
        ConfigurationBuilder cb = new ConfigurationBuilder();

        cb.setDebugEnabled(true)
                .setOAuthConsumerKey("bsLe0WHSAc7oGoLcCupRw06JG")
                .setOAuthConsumerSecret("F3yKLGtr0mX1SgL0nHK0U5Fj02RWG8krNTja6Rbf3sSU7ZmAAl")
                .setOAuthAccessToken("1140683195245051904-hMZoyExFsnnzAXtkUm8JTYNUmfkgQq")
                .setOAuthAccessTokenSecret("5PMd7AoK2KN7iw9QkSQDVLvzuJ3jcYbsqqPt8j4w5ETyi");

        TwitterFactory tf = new TwitterFactory(cb.build());
        twitter4j.Twitter twitter = tf.getInstance();

        ArrayList <String> tweetLine = new ArrayList<>();

        try {

            List <Status> status = twitter.getHomeTimeline();

            for(Status st : status) {

                tweetUser = st.getUser().getName().toUpperCase();
                tweetContent = st.getText();
                totalTweet = tweetUser + "          " + tweetContent + "\n";
                tweetLine.add(totalTweet);

            }

        } catch (TwitterException t) {

            tweetLine.add(totalTweet);

        }

        ArrayAdapter <String> tweetAdapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,tweetLine);
        tweetView.setAdapter(tweetAdapter);

    }

    public boolean onTouchEvent(MotionEvent touchevent) {

        switch(touchevent.getAction()) {

            case MotionEvent.ACTION_DOWN:
                x1 = touchevent.getX();
                y1 = touchevent.getY();
                break;
            case MotionEvent.ACTION_UP:
                x2 = touchevent.getX();
                y2 = touchevent.getY();
                if(x1 > x2) {
                    Intent i = new Intent(TwitterFeed.this, RealEstate.class);
                    startActivity(i);
                }
                break;

        }

        return false;

    }

}

我希望输出是列表视图中每个项目的一系列推文,但它只是显示一个空白屏幕。再说一次,没有代码给我一个错误。

0 个答案:

没有答案