每日新闻app客户端开发

main_activity1:

public void onclick1(View view) {
        String name1=e1.getText().toString().trim();
        String name2=e2.getText().toString().trim();
        if(name1.equals("12345")||name2.equals("12345")){
            final ProgressDialog pd = new ProgressDialog(this);
            pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            pd.setMax(100);
            pd.setTitle("加载");
            pd.setMessage("进度");
            pd.show();
            new Thread() {
                public void run() {
                    for (int i = 0; i <= 100; i++) {
                        try {
                            Thread.sleep(3);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        pd.setProgress(i);
                    }
                    pd.dismiss();
                };
            }.start();
            Intent intent =new Intent();
            intent.setClass(MainActivity1.this,MainActivity3.class);
            startActivity(intent);
        }
        else{
            Toast.makeText(MainActivity1.this,"错误",Toast.LENGTH_SHORT).show();}

    }
    public void onclick2(View view) {
        Intent intent =new Intent();
        intent.setClass(MainActivity1.this,MainActivity2.class);
        startActivity(intent);
    }
}

main_activity2:

public void onclick5(View view) {
            String name1=e3.getText().toString().trim();
            String name2=e4.getText().toString().trim();
            Intent intent = new Intent(MainActivity2.this,MainActivity1.class);
            intent.putExtra("name1",name1);
            intent.putExtra("name2",name2);
            startActivity(intent);
        }

main_activity3:

public class MainActivity3 extends AppCompatActivity {

    private ListView lv;
    private List<NewsItem> allNews;
    private Handler handler  = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            allNews =  ( List<NewsItem>)msg.obj;
            lv.setAdapter(new MyAdapter());
        }
    };

    private String[] url={"http://shizheng.xilu.com/20150212/1000150003885927.html","https://baijiahao.baidu.com/s?id=1710022549162689199&wfr=spider&for=pc"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        lv = findViewById(R.id.lv);

        Button yyButton = findViewById(R.id.startYY);
        yyButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = null;
                PackageManager pm = getPackageManager();
                PackageInfo pi = null;
                try {
                    pi = pm.getPackageInfo("com.iflytek.voicedemo", 0);
                } catch (PackageManager.NameNotFoundException e) {
                    e.printStackTrace();
                }
                Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
                resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                resolveIntent.setPackage(pi.packageName);


                //找到匹配intent的所有Activity,这个方法可以在intent跳转前调用用来检测是否有符合条件的activity
                List<ResolveInfo> apps = pm.queryIntentActivities(resolveIntent, 0);
                ResolveInfo ri = apps.iterator().next();
                if (ri != null) {
                    String className = ri.activityInfo.name;

                    intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);

                    ComponentName cn = new ComponentName("com.iflytek.voicedemo", className);

                    intent.setComponent(cn);
                }
                startActivity(intent);
            }
        });



        new Thread(){
            @Override
            public void run() {

                try {
                    allNews =  NewsInfoService.getAllNews("http://192.168.43.80:8080/news.xml");
                    Message msg=  new Message();
                    msg.obj = allNews;
                    handler.sendMessage(msg);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return allNews.size();
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup viewGroup) {




            View view = View.inflate(MainActivity3.this, R.layout.item, null);

            TextView tv_title = (TextView) view.findViewById(R.id.tv_item_title);
            TextView tv_desc = (TextView) view.findViewById(R.id.tv_item_desc);
            TextView tv_comment = (TextView) view.findViewById(R.id.tv_item_comment);
            ImageView siv = (ImageView) view.findViewById(R.id.iv_item);
            view.findViewById(R.id.tv_item_but).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(url[position]));
                    startActivity(intent);
                }
            });
            NewsItem item = allNews.get(position);
            tv_title.setText(item.getTitle());
            tv_desc.setText(item.getDescription());
            String type = item.getType();//1  2 3
            if("1".equals(type)){
                tv_comment.setText("评论数:"+item.getComment());
            }else if("2".equals(type)){
                tv_comment.setText("视频");
                tv_comment.setBackgroundColor(0x66ff0000);
            }else if("3".equals(type)){
                tv_comment.setText("LIVE");
                tv_comment.setBackgroundColor(0x660000ff);
            }
            System.out.println(item.getImage());

            Glide.with(MainActivity3.this)
                    .load(item.getImage())
                    .placeholder(R.mipmap.ic_launcher)
                    .error(R.mipmap.ic_launcher)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(siv);
            return view;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

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


    }

相关详细的布局文件及完整的每日新闻app项目代码在上传资源中。

1、登录界面 

每日新闻app客户端开发 

2、注册界面 

每日新闻app客户端开发 

3、新闻列表界面 

 每日新闻app客户端开发

4、语音识别功能

每日新闻app客户端开发 

 

 

 

 

 

 

 

 

 

 

上一篇:Mirror for Samsung TV for mac(三星智能电视投屏软件)


下一篇:Android TV端电视直播软件 和 投屏工具