问题描述
即时通讯开发一个Android应用程序,我想补充意见,以行其选择的用户的用户来选择要do.An例如这种执行下一个在Twitter的羽流应用程序发现...我不知道如何去它。我已实现了以下code,但关注的是工作。
teaam_list.setOnItemClickListener(新AdapterView.OnItemClickListener(){
@覆盖
公共无效onItemClick(适配器视图<>适配器视图,视图中查看,INT I,长L){
按钮BTN =新按钮(getActivity());
btn.setText(与点击添加);
ArrayList的<视图> VS =新的ArrayList<视图>();
vs.add(BTN);
view.addChildrenForAccessibility(VS);
view.invalidate();
}
});
我做这个工作的另一种方式为我的需要。在这里,当列表项用户点击即可额外的观点仅仅是补充,列表项的下面。如果你再次点击则认为被最小化。对于那些你可以这样做:
1)初始化您的ListView:
mListView =(ListView控件)findViewById(R.id.lv_settings_list);
mSettingListArrayAdapter =新SettingsListAdapter(这一点,R.layout.list_items,
mSettingsArrayList);
mSettingListArrayAdapter.notifyDataSetChanged();
mListView.setAdapter(mSettingListArrayAdapter);
mListView.setOnItemClickListener(本);
2)添加onItemClickListener:
@覆盖
公共无效onItemClick(适配器视图<>母公司视图中查看,INT位置,长的id){
视图工具栏= view.findViewById(R.id.toolbar);
ExpandAnimation expandAnimation =新ExpandAnimation(工具栏,500);
toolbar.startAnimation(expandAnimation);
}
3)班的动画:
公共类ExpandAnimation扩展动画{
私人查看mAnimatedView;
私人的LayoutParams mViewLayoutParams;
私人诠释mMarginStart,mMarginEnd;
私人布尔mIsVisibleAfter = FALSE;
私人布尔mWasEndedAlready = FALSE;
公共ExpandAnimation(查看视图,INT持续时间){
setDuration(持续时间);
mAnimatedView =图。
mViewLayoutParams =(的LayoutParams)view.getLayoutParams();
mIsVisibleAfter =(view.getVisibility()== View.VISIBLE);
mMarginStart = mViewLayoutParams.bottomMargin;
mMarginEnd =(mMarginStart == 0(0 - view.getHeight()):0);
view.setVisibility(View.VISIBLE);
}
@覆盖
保护无效applyTransformation(浮动interpolatedTime,变换T){
super.applyTransformation(interpolatedTime,T);
如果(interpolatedTime< 1.0F){
//计算新的底部边缘,并将其设置
mViewLayoutParams.bottomMargin = mMarginStart +(INT)((mMarginEnd - mMarginStart)* interpolatedTime);
//无效化的布局,使我们看到我们所做的更改
mAnimatedView.requestLayout();
//确保我们没有运行结束之前(它发生!)
}否则,如果(!mWasEndedAlready){
mViewLayoutParams.bottomMargin = mMarginEnd;
mAnimatedView.requestLayout();
如果(mIsVisibleAfter){
mAnimatedView.setVisibility(View.GONE);
}
mWasEndedAlready = TRUE;
}
}
}
4)查看将被添加onItemClick:
<的LinearLayout
机器人:ID =@ + ID /工具栏
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginBottom = - 50dip
机器人:分隔=#6F8290
机器人:重力=右
机器人:能见度=水涨船高>
< ImageView的
机器人:ID =@ + ID / iv_edit
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:可聚焦=假
机器人:paddingRight =5dip
机器人:focusableInTouchMode =假
机器人:SRC =@可绘制/编辑/>
< ImageView的
机器人:ID =@ + ID / iv_delete
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:可聚焦=假
机器人:以下属性来=5dip
机器人:focusableInTouchMode =假
机器人:paddingRight =10dip
机器人:SRC =@可绘制/删除
机器人:能见度=水涨船高/>
< / LinearLayout中>
这就是全部。我认为这将帮助你。
Im developing an android app and i want to add views to the row on which the user selected for the user to select what next to do.An example of such implementation is found in the plume app for twitter...i dont know how to go about it.I have implemented the following code but noting is working.
teaam_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Button btn= new Button(getActivity());
btn.setText("added with click");
ArrayList<View> vs= new ArrayList<View>();
vs.add(btn);
view.addChildrenForAccessibility(vs);
view.invalidate();
}
});
I do this work another way for my need. Here when user click on list item then an additional view is just added below of that list item. If you clicked again then view is minimized. For that you can do this :
1) Initialize your listview :
mListView = (ListView) findViewById(R.id.lv_settings_list);
mSettingListArrayAdapter = new SettingsListAdapter(this, R.layout.list_items,
mSettingsArrayList);
mSettingListArrayAdapter.notifyDataSetChanged();
mListView.setAdapter(mSettingListArrayAdapter);
mListView.setOnItemClickListener(this);
2) Add onItemClickListener :
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
View toolbar = view.findViewById(R.id.toolbar);
ExpandAnimation expandAnimation = new ExpandAnimation(toolbar, 500);
toolbar.startAnimation(expandAnimation);
}
3) Class for animation :
public class ExpandAnimation extends Animation {
private View mAnimatedView;
private LayoutParams mViewLayoutParams;
private int mMarginStart, mMarginEnd;
private boolean mIsVisibleAfter = false;
private boolean mWasEndedAlready = false;
public ExpandAnimation(View view, int duration) {
setDuration(duration);
mAnimatedView = view;
mViewLayoutParams = (LayoutParams) view.getLayoutParams();
mIsVisibleAfter = (view.getVisibility() == View.VISIBLE);
mMarginStart = mViewLayoutParams.bottomMargin;
mMarginEnd = (mMarginStart == 0 ? (0 - view.getHeight()) : 0);
view.setVisibility(View.VISIBLE);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
if (interpolatedTime < 1.0f) {
// Calculating the new bottom margin, and setting it
mViewLayoutParams.bottomMargin = mMarginStart + (int) ((mMarginEnd - mMarginStart) * interpolatedTime);
// Invalidating the layout, making us seeing the changes we made
mAnimatedView.requestLayout();
// Making sure we didn't run the ending before (it happens!)
} else if (!mWasEndedAlready) {
mViewLayoutParams.bottomMargin = mMarginEnd;
mAnimatedView.requestLayout();
if (mIsVisibleAfter) {
mAnimatedView.setVisibility(View.GONE);
}
mWasEndedAlready = true;
}
}
}
4) View which will be added onItemClick:
<LinearLayout
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-50dip"
android:divider="#6F8290"
android:gravity="right"
android:visibility="gone" >
<ImageView
android:id="@+id/iv_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:paddingRight="5dip"
android:focusableInTouchMode="false"
android:src="@drawable/edit" />
<ImageView
android:id="@+id/iv_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:paddingLeft="5dip"
android:focusableInTouchMode="false"
android:paddingRight="10dip"
android:src="@drawable/delete"
android:visibility="gone" />
</LinearLayout>
That's all. I think it will help you.
这篇关于当选择了它添加视图到ListView的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!