修改了一部分代码,使用listview实现了浏览信息

my
盛洁 5 years ago
parent 31d74910aa
commit c1bd6ae582

@ -8,9 +8,12 @@ import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import android.os.Handler;
import android.os.Message;
import android.view.MenuItem;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.ListFragment;
@ -46,6 +49,15 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
Context mContext;
private NewsAdapter newsAdapter;
private ListView lv_news;
private Handler mhandler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if(msg.what==1){
newsAdapter.notifyDataSetChanged();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -143,8 +155,11 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
private class UploadThread extends Thread{
@Override
public void run() {
NewsUtils.getAllNews(mContext,list);
newsAdapter.notifyDataSetChanged();
Message message = mhandler.obtainMessage();
int isload = NewsUtils.getAllNews(mContext,list);
message.what = isload;
mhandler.sendMessage(message);
//newsAdapter.notifyDataSetChanged();
}
}

Loading…
Cancel
Save