流式布局点击字幕 跳转页面

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.activity.MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:layout_weight="1"
            android:id="@+id/flow_sou"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="默认数据"
            />
        <Button
            android:id="@+id/flow_buten"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="搜索"/>
    </LinearLayout>
 <com.zhy.view.flowlayout.TagFlowLayout
     android:id="@+id/flowlayout"
     tools:max_select="-1"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:padding="20dp"
     >

 </com.zhy.view.flowlayout.TagFlowLayout>
</LinearLayout>

main.activity

public class MainActivity extends AppCompatActivity {

    @BindView(id.flow_sou)
    EditText flowSou;
    @BindView(id.flow_buten)
    Button flowButen;
    @BindView(id.flowlayout)
    TagFlowLayout flowlayout;
    private ArrayList<String> strings;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layout.activity_main);
        ButterKnife.bind(this);
        strings = new ArrayList<>();
        flowlayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
           @Override
           public boolean onTagClick(View view, int position, FlowLayout parent) {
               Intent intent = new Intent(MainActivity.this,ShowActivity.class);
               startActivity(intent);
               return false;
           }
       });
    }

    @OnClick(id.flow_buten)
    public void onViewClicked() {
        String flowsou = flowSou.getText().toString();
       strings.add(flowsou);
       flowlayout.setAdapter(new TagAdapter<String>(strings) {

           @Override
           public View getView(FlowLayout parent, int position, String s) {
               TextView view = (TextView) LayoutInflater.from(MainActivity.this).inflate(layout.tvitem, flowlayout, false);
               view.setText(s);
               return view;
           }
       });
    }
}

3tvtime.xml

<?xml version="1.0" encoding="utf-8"?>

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tv_itme"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="20dp"
    />

4 跳转页面

public class ShowActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);
    }
}

猜你喜欢

转载自blog.csdn.net/qq_41880253/article/details/82013287
今日推荐