Android timeline, android

Source: Internet
Author: User

Android timeline, android

:



Scrollview + listView stack nesting

Do not slide ListView:

Import android. content. context; import android. util. attributeSet; import android. widget. listView; public class MyListView extends ListView {public MyListView (Context context, AttributeSet attrs) {super (context, attrs );} /*** set not to scroll */public void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {int expandSpec = MeasureSpec. makeMeasureSpec (Integer. MAX_VALUE> 2, MeasureSpec. AT_MOST); super. onMeasure (widthMeasureSpec, expandSpec );}}
MainActivity:

import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.LinearLayout;import android.widget.TextView;public class MainActivity extends Activity {private LinearLayout layout_parent1;private LinearLayout layout_parent2;private TextView year;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);layout_parent1=(LinearLayout)findViewById(R.id.layout_parent1);initView();}private void initView() {// TODO Auto-generated method stubArrayList<AdapterBean> list=AdapterBean.getAdapterBeanCollection();for (int i = 0; i < list.size(); i++) {View view=getLayoutInflater().inflate(R.layout.item_scroll, null);layout_parent2=(LinearLayout)view.findViewById(R.id.layout_parent2);year=(TextView)view.findViewById(R.id.textView_year);year.setText(list.get(i).getYear());layout_parent2.addView(ChildView.getInstance(getLayoutInflater()).getView());layout_parent1.addView(view);}}}

ChildView:

import android.view.LayoutInflater;import android.view.View;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.Toast;public class ChildView implements OnItemClickListener{public static ChildView child=null;private static LayoutInflater inflater;public static ChildView getInstance(LayoutInflater layoutInflater) {// TODO Auto-generated method stubinflater=layoutInflater;return new ChildView(layoutInflater);}private View view;private MyListView noScrolistview;private MyAdapter adapter;public ChildView(LayoutInflater layoutInflater){view=layoutInflater.inflate(R.layout.item_main, null);initialization();}private void initialization() {// TODO Auto-generated method stubnoScrolistview=(MyListView)view.findViewById(R.id.NoScrollListview);adapter=new MyAdapter(inflater,TestBean.getTestBeanCollection());noScrolistview.setAdapter(adapter);noScrolistview.setOnItemClickListener(this);}public View getView() {// TODO Auto-generated method stubreturn view;}@Overridepublic void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {// TODO Auto-generated method stubToast.makeText(inflater.getContext(), "Position:  "+position, Toast.LENGTH_SHORT).show();}}
If you need to classify the number, the same is true.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.