所以基本上,我有一个自定义列表视图,有类似,不喜欢和其他很少的按钮,这些按钮会在点击时改变它们的状态。现在我遇到的问题是,当我点击“说”,类似按钮时,查询就会被传递(即使在后端),它也会成功获得,但只要我向上或向下滚动该特定列表项,它就会返回到加载列表时的初始状态。我寻找了很多解决方案,将布局设为fill_parent,但仍然无法正常工作。请有人帮帮我!
P.S我附加了2张图片,1)当我喜欢并且计数器从1变为2. 2)当我向下滚动并备份时它变回1
XML代码 -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lsk"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#34495e"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#34495e"
android:tabStripEnabled="false"
android:minHeight="?attr/actionBarSize"
android:fillViewport="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="100dp"
android:layout_height="100dp"
app:borderWidth="0dp"
app:elevation="6dp"
android:backgroundTint="#ecf0f1"
android:layout_gravity="bottom|end"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/upc" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_main_swipe_refresh_layoutqaqq"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/tabLayout"
>
<ListView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/lvScribe"
android:divider="@null"
android:layout_below="@+id/tabLayout"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
适配器代码 -
public View getView(final int position, View convertView, ViewGroup parent) {
Log.e("sd","getView " + position + " " + convertView);
final FeedItem item = feedItems.get(position);
final ImageButton collec;
if(convertView==null){
Log.e("in", "" + "null");
}else {
Log.e("in", "" + "not null");
}
if(item.getViewType()==2) {
Log.e("in", "" + (feedItems.size() + (feedItems.size() / 9)));
if (convertView == null)
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.adview, null);
NativeExpressAdView adView = (NativeExpressAdView)convertView.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice("0FF63ABD3E239F0EF3B0F21A90772205").build();
adView.loadAd(adRequest);
//n=n+6;
} else {
if (convertView == null)
Log.e("conver",""+convertView);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.feed_item, null);
ss = new SharedPrefs(context);
imageLoader = AppController.getInstance().getImageLoader();
TextView name = (TextView) convertView.findViewById(R.id.name);
TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp);
TextView tt = (TextView) convertView.findViewById(R.id.title);
ImageView meme = (ImageView) convertView.findViewById(R.id.imageView);
ImageView profilePic = (ImageView) convertView.findViewById(R.id.profilePic);
FeedImageView feedImageView = (FeedImageView) convertView.findViewById(R.id.feedImage1);
final ImageButton like = (ImageButton) convertView.findViewById(R.id.button1);
final ImageButton dlike = (ImageButton) convertView.findViewById(R.id.button2);
final TextView co = (TextView) convertView.findViewById(R.id.te);
collec = (ImageButton) convertView.findViewById(R.id.button3);
ImageButton comm = (ImageButton) convertView.findViewById(R.id.button4);
final ImageButton rep = (ImageButton) convertView.findViewById(R.id.button5);
tag = "" + like.getTag();
imgLoader = new ImageLoaderr(context);
return convertView;
}