• 今日总结


    2021年2月8日:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/grey_f3f3f3">
    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="50dp">
    <ImageView
    android:id="@+id/record_iv_back"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:src="@mipmap/ih_error"
    android:onClick="onClick"
    android:layout_marginLeft="10dp"/>
    <com.google.android.material.tabs.TabLayout
    android:id="@+id/record_tabs"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    app:tabGravity="center"
    app:tabMode="fixed"
    app:tabTextColor="@color/grey_7D7D7D"
    app:tabSelectedTextColor="@color/black"
    app:tabIndicatorColor="@color/black"/>
    </RelativeLayout>
    <androidx.viewpager.widget.ViewPager
    android:id="@+id/record_vp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
    </LinearLayout>

     适配器:

    package com.example.jiatingruanjian.adapter;

    import androidx.annotation.NonNull;
    import androidx.annotation.Nullable;
    import androidx.fragment.app.Fragment;
    import androidx.fragment.app.FragmentManager;
    import androidx.fragment.app.FragmentPagerAdapter;

    import java.util.List;

    public class RecordPagerAdapter extends FragmentPagerAdapter {
    List<Fragment>fragmentList;
    String[]titles = {"支出","收入"};
    public RecordPagerAdapter(@NonNull FragmentManager fm,List<Fragment>fragmentList) {
    super(fm);
    this.fragmentList = fragmentList;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
    return fragmentList.get(position);
    }

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

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
    return titles[position];
    }
    }


    RecordActivity:
    package com.example.jiatingruanjian;
    import android.os.Bundle;
    import android.view.View;
    import androidx.appcompat.app.AppCompatActivity;
    import androidx.fragment.app.Fragment;
    import androidx.viewpager.widget.ViewPager;
    import com.example.jiatingruanjian.adapter.RecordPagerAdapter;
    import com.example.jiatingruanjian.frag_record.IncomeFragment;
    import com.example.jiatingruanjian.frag_record.OutcomeFragment;
    import com.google.android.material.tabs.TabLayout;
    import java.util.ArrayList;
    import java.util.List;
    public class RecordActivity extends AppCompatActivity {
    TabLayout tabLayout;
    ViewPager viewPager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_record);
    //1.查找控件
    tabLayout = findViewById(R.id.record_tabs);
    viewPager = findViewById(R.id.record_vp);
    //2.设置ViewPager加载页面
    initPager();
    }

    private void initPager() {
    // 初始化ViewPager页面的集合
    List<Fragment>fragmentList = new ArrayList<>();
    // 创建收入和支出页面,放置在Fragment当中
    OutcomeFragment outFrag = new OutcomeFragment(); //支出
    IncomeFragment inFrag = new IncomeFragment(); //收入
    fragmentList.add(outFrag);
    fragmentList.add(inFrag);

    // 创建适配器
    RecordPagerAdapter pagerAdapter = new RecordPagerAdapter(getSupportFragmentManager(), fragmentList);
    // 设置适配器
    viewPager.setAdapter(pagerAdapter);
    //将TabLayout和ViwePager进行关联
    tabLayout.setupWithViewPager(viewPager);
    }

    /* 点击事件*/
    public void onClick(View view) {
    switch (view.getId()) {
    case R.id.record_iv_back:
    finish();
    break;
    }
    }
    }

    Seacher.xml:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/grey_f3f3f3">
    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="50dp">
    <ImageView
    android:id="@+id/search_iv_back"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:onClick="onClick"
    android:layout_marginLeft="10dp"
    android:src="@mipmap/it_back"/>
    <EditText
    android:id="@+id/search_et"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/search_iv_back"
    android:background="@drawable/dialog_btn_bg"
    android:layout_centerVertical="true"
    android:textSize="16sp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:paddingLeft="20dp"
    android:layout_marginLeft="10dp"
    android:hint="@string/please_search_info">
    <requestFocus/>
    </EditText>
    <ImageView
    android:id="@+id/search_iv_sh"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@mipmap/search"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="20dp"
    android:onClick="onClick"/>
    </RelativeLayout>
    <ListView
    android:id="@+id/search_lv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:dividerHeight="6dp"
    android:divider="@color/grey_f3f3f3"
    />
    <TextView
    android:id="@+id/search_tv_empty"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/date_empty"
    android:gravity="center"
    android:textSize="20sp"
    android:drawableTop="@mipmap/it_searchtext"
    android:layout_marginTop="250dp"/>

    </LinearLayout>

    SeacherActivity:

    package com.example.jiatingruanjian;

    import android.os.Bundle;
    import android.text.TextUtils;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.ListView;
    import android.widget.TextView;
    import android.widget.Toast;

    import androidx.appcompat.app.AppCompatActivity;

    import com.example.jiatingruanjian.adapter.AccountAdapter;
    import com.example.jiatingruanjian.db.AccountBean;
    import com.example.jiatingruanjian.db.DBManager;

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


    public class SearchActivity extends AppCompatActivity {
    ListView searchLv;
    EditText searchEt;
    TextView emptyTv;
    List<AccountBean> mDatas; //数据源
    AccountAdapter adapter; //适配器对象
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    initView();
    mDatas = new ArrayList<>();
    adapter = new AccountAdapter(this,mDatas);
    searchLv.setAdapter(adapter);
    searchLv.setEmptyView(emptyTv); //设置无数局时,显示的控件
    }

    private void initView() {
    searchEt = findViewById(R.id.search_et);
    searchLv = findViewById(R.id.search_lv);
    emptyTv = findViewById(R.id.search_tv_empty);
    }

    public void onClick(View view) {
    switch (view.getId()) {
    case R.id.search_iv_back:
    finish();
    break;
    case R.id.search_iv_sh: //执行搜索的操作
    String msg = searchEt.getText().toString().trim();
    // 判断输入内容是否为空,如果为空,就提示不能搜索
    if (TextUtils.isEmpty(msg)) {
    Toast.makeText(this,"输入内容不能为空!",Toast.LENGTH_SHORT).show();
    return;
    }
    //开始搜索
    List<AccountBean> list = DBManager.getAccountListByRemarkFromAccounttb(msg);
    mDatas.clear();
    mDatas.addAll(list);
    adapter.notifyDataSetChanged();
    break;
    }
    }
    }
  • 相关阅读:
    (一) kinect概述
    (五)摇杆/按钮/触摸板
    (四)Trigger
    (三)快速添加touch事件
    (二)简单触控
    Java程序设计当堂测试 9.20
    Java程序设计当堂测试感受
    暑假生活第八周总结
    暑假生活第七周总结
    暑假生活第六周总结
  • 原文地址:https://www.cnblogs.com/yitiaokuailedexiaojingyu/p/14390759.html
Copyright © 2020-2023  润新知