- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现一个“Collection 夹”系统,因此当一个产品被选为 Collection 夹(通过单击按钮)时,它会被传递到一个名为 Favoris.java 的类,该类将所有 Collection 夹的产品显示为 ListView,这些都是可点击的,以获取有关所点击产品的更多详细信息。到目前为止,listview 工作正常。
但这是我的主要问题:当我单击其中一个产品以获取其详细信息时,显示的是另一个不在 Collection 夹列表中的产品。
我确实注意到了一些可能会有所帮助的事情:通过在我的列表中添加一些 Collection 夹,比如 3,我注意到了一种模式:
我目前通过使用 Gson 转换它并使用 SharedPrefenreces 传递它,将最喜欢的产品作为类对象传递给 Collection 夹类,然后类 Favoris.java 取回该产品并将其转换回类对象。
这是我所有我最喜欢的产品的 ListView ,您可以看到有 4 个产品添加为 Collection :
当单击第一个产品 (Palais Héracles) 时,我会看到另一个名为“Château Périgord”的产品(默认产品列表中的第一个)(你可以看到我没有将它添加为 Collection 夹,因为星形图标不是黑色而是白色):
这是产品详情的代码:
public class ProduitDetail extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
/**
* fields
*/
private StackProduits produit;
private Button butStar;
/*images (main, thumbnails and gallery)*/
private ArrayList<String> imagesUrlListThumb, imagesUrlListFull = new ArrayList<String>();
private RecyclerAdapter recyclerAdapter;
private String urlRecyclerThumb = "";
/*view elements*/
private RecyclerView recyclerView;
private ImageView imgCurRecyclerView;
private Button btnMailCurProduct, btnMailAgency;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_produit_detail);
/*get ids of the two star icons*/
final int imgStarFull = R.drawable.ic_star;
final int imgStarBorder = R.drawable.ic_star_border;
/*get view references from content_produit_detail.xml*/
butStar = (Button) findViewById(R.id.button_detail_heart);
/*get produit class object from both Ventes.java and Location.java*/
produit = new StackProduits();
Intent intent = getIntent();
produit = intent.getParcelableExtra("produit");
/**handle favorites icon turned on or off when entering the product detail*/
final SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Set<String> jsonList = mPrefs.getStringSet("listJson2", new HashSet<String>());
Set<String> jsonList2 = new HashSet<>();
jsonList2.addAll(jsonList);
produit.setIsAddedAsFav("1");
Gson gson = new Gson();
String myJson = gson.toJson(produit);
if (jsonList2.contains(myJson)) {
butStar.setCompoundDrawablesWithIntrinsicBounds(imgStarFull, 0, 0, 0);
} else {
produit.setIsAddedAsFav("0");
}
/**
* Listener for the star button used to make the current product favorite by adding it to a
* list of all the products currently set as favorite
*/
butStar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/*Change the icon and make a toast when the heart button is pressed*/
if (produit.getIsAddedAsFav().equalsIgnoreCase("0")) {
produit.setIsAddedAsFav("1");
butStar.setCompoundDrawablesWithIntrinsicBounds(imgStarFull, 0, 0, 0);
SharedPreferences.Editor prefsEditor = mPrefs.edit();
Gson gson = new Gson();
//convert product to string via gson
String myJson = gson.toJson(produit);
//prefsEditor.putString("MyObject", myJson);
//get the Set<String> reference back to keep the entire list of favorites
Set<String> jsonList = mPrefs.getStringSet("listJson2", new HashSet<String>());
//make a copy of Set<String> pref to make it usable
Set<String> jsonList2 = new HashSet<>();
//add the list and the new product to the copy of Set<String>
jsonList2.addAll(jsonList);
jsonList2.add(myJson);
//add list to editor
prefsEditor.putStringSet("listJson2", jsonList2);
prefsEditor.apply();
Toast.makeText(ProduitDetail.this, getString(R.string.toast_favorite_added), Toast.LENGTH_SHORT).show();
} else {
produit.setIsAddedAsFav("1");
butStar.setCompoundDrawablesWithIntrinsicBounds(imgStarBorder, 0, 0, 0);
SharedPreferences.Editor prefsEditor = mPrefs.edit();
Set<String> jsonList = mPrefs.getStringSet("listJson2", new HashSet<String>());
Set<String> jsonList2 = new HashSet<>();
jsonList2.addAll(jsonList);
Gson gson = new Gson();
String myJson = gson.toJson(produit);
jsonList2.remove(myJson);
prefsEditor.putStringSet("listJson2", jsonList2);
prefsEditor.apply();
produit.setIsAddedAsFav("0");
Toast.makeText(ProduitDetail.this, getString(R.string.toast_favorite_removed), Toast.LENGTH_SHORT).show();
}
}
});
}
}
这是我的类处理 Collection 夹的代码:
public class Favoris extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
/**fields*/
private ListView produitFavorisListView;
private List<StackProduits> listProduits = new ArrayList<>();
private ProduitsAdapter adapterFavoris;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_favoris);
/*get ListView reference*/
produitFavorisListView = (ListView) findViewById(R.id.favoritesList);
/*getting back data from shared preferences*/
final SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
final Gson gson = new Gson();
//getting back favorites
Set<String> myJson = mPrefs.getStringSet("listJson2", new HashSet<String>());
if (myJson.isEmpty() && listProduits.isEmpty()) {
produitFavorisListView.setAdapter(null);
}
else if (myJson.isEmpty() && listProduits != null) {
adapterFavoris.notifyDataSetChanged();
adapterFavoris = new ProduitsAdapter(getApplicationContext(), -1, listProduits);
produitFavorisListView.setAdapter(adapterFavoris);
}
else{
//for each where we get back values from sting set, then convert to product
for (String id : myJson) {
StackProduits savedProduct = gson.fromJson(id, StackProduits.class);
listProduits.add(savedProduct);
}
adapterFavoris = new ProduitsAdapter(getApplicationContext(), -1, listProduits);
produitFavorisListView.setAdapter(adapterFavoris);
}
//Set the click listener to launch the browser when a row is clicked.
produitFavorisListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
Intent intentProduitFavorisDetail = new Intent(Favoris.this, ProduitDetail.class);
StackProduits ProduitFavoris = ProduitsXmlPullParser.getStackProduitFromFile(Favoris.this).get(pos);
intentProduitFavorisDetail.putExtra("produit", ProduitFavoris);
startActivity(intentProduitFavorisDetail);
}
});
}
}
这是我最喜欢的 ListView 的布局:
<?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:padding="13dp"
android:layout_marginTop="55dp">
<TextView
android:id="@+id/content_favorite_emptylist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:visibility="gone"
android:textColor="#343232"
android:textSize="18sp"
android:textStyle="bold"/>
<ListView
android:id="@+id/favoritesList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
这是我的适配器类:
public class ProduitsAdapter extends ArrayAdapter<StackProduits> {
/**
* fields
*/
ImageLoader imageLoader;
DisplayImageOptions options;
List<StackProduits> productList;
SparseBooleanArray mSelectedItemsIds;
public ProduitsAdapter(Context ctx, int textViewResourceId, List<StackProduits> sites) {
super(ctx, textViewResourceId, sites);
/**Setup the ImageLoader, we'll use this to display our images*/
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(ctx).build();
imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
mSelectedItemsIds = new SparseBooleanArray();
/**Setup options for ImageLoader so it will handle caching for us.*/
options = new DisplayImageOptions.Builder()
.cacheInMemory()
.cacheOnDisc()
.build();
}
/**
* This method is responsible for creating row views out of a StackProduits object that can be put
* into our ListView.
* <p/>
* (non-Javadoc)
*
* @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
*/
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
RelativeLayout row = (RelativeLayout) convertView;
//Log.i("StackSites", "getView pos = " + pos);
if (null == row) { //No recycled View, we have to inflate one.
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = (RelativeLayout) inflater.inflate(R.layout.item_row, null);
}
//Get our View References from item_row.xml
final ImageView iconImg = (ImageView) row.findViewById(R.id.iconImg);
TextView txtDesignation = (TextView) row.findViewById(R.id.nameTxt);
TextView txtAbout = (TextView) row.findViewById(R.id.aboutTxt);
TextView txtPrice = (TextView) row.findViewById(R.id.priceTxt);
TextView txtTotalArea = (TextView) row.findViewById(R.id.areaTxt);
final ProgressBar indicator = (ProgressBar) row.findViewById(R.id.progress);
//Initially we want the progress indicator visible, and the image invisible
indicator.setVisibility(View.VISIBLE); //show progress indicator
iconImg.setVisibility(View.INVISIBLE); //make image invisible
//Setup a listener we can use to switch from the loading indicator to the Image once it's ready
//changed ImageLoadingListener with SimpleImageLoadingListener
SimpleImageLoadingListener listener = new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String arg0, View arg1) {
// TODO Auto-generated method stub
}
@Override
public void onLoadingCancelled(String arg0, View arg1) {
// TODO Auto-generated method stub
}
@Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
indicator.setVisibility(View.INVISIBLE);
iconImg.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
// TODO Auto-generated method stub
}
};
//Load the image and use our options so caching is handled.
imageLoader.displayImage(getItem(pos).getImgUrl(), iconImg, options, listener);
//Set the relevant text in our TextViews (ListView)
txtDesignation.setText(getItem(pos).getDesignation());
txtAbout.setText(getItem(pos).getAbout());
txtPrice.setText(getItem(pos).getPrice());
txtTotalArea.setText(getItem(pos).getArea());
//return view that represents the full row
return row;
}
}
在 onItemClick 中的 Logcat (Favoris.java)
Log.i("test", adapterFavoris.getItem(pos).toString());
07-13 13:27:27.907 1613-1613/com.example.adam_jaamour.cfimmobilier W/System: ClassLoader referenced unknown path: /data/app/com.example.adam_jaamour.cfimmobilier-2/lib/x86
07-13 13:27:30.020 1613-1613/com.example.adam_jaamour.cfimmobilier W/System: ClassLoader referenced unknown path: /data/app/com.example.adam_jaamour.cfimmobilier-2/lib/x86
07-13 13:27:30.169 1613-1613/com.example.adam_jaamour.cfimmobilier W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-13 13:27:30.380 1613-1701/com.example.adam_jaamour.cfimmobilier D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[ 07-13 13:27:30.388 1613: 1613 D/ ]
HostConnection::get() New Host Connection established 0xaa979e80, tid 1613
[ 07-13 13:27:30.414 1613: 1701 D/ ]
HostConnection::get() New Host Connection established 0xaa9796d0, tid 1701
07-13 13:27:30.418 1613-1701/com.example.adam_jaamour.cfimmobilier I/OpenGLRenderer: Initialized EGL, version 1.4
07-13 13:27:31.015 1613-1613/com.example.adam_jaamour.cfimmobilier I/Choreographer: Skipped 33 frames! The application may be doing too much work on its main thread.
07-13 13:27:32.408 1613-1613/com.example.adam_jaamour.cfimmobilier E/libEGL: call to OpenGL ES API with no current context (logged once per thread)
07-13 13:27:32.649 1613-1701/com.example.adam_jaamour.cfimmobilier E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa2329ad0
07-13 13:27:36.071 1613-1613/com.example.adam_jaamour.cfimmobilier W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=161.13647, y[0]=1479.668, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=16698889, downTime=16695116, deviceId=0, source=0x1002 }
07-13 13:27:36.071 1613-1613/com.example.adam_jaamour.cfimmobilier W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=161.13647, y[0]=1479.668, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=16698889, downTime=16695116, deviceId=0, source=0x1002 }
07-13 13:27:36.072 1613-1613/com.example.adam_jaamour.cfimmobilier W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=161.13647, y[0]=1479.668, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=16698889, downTime=16695116, deviceId=0, source=0x1002 }
07-13 13:27:36.072 1613-1613/com.example.adam_jaamour.cfimmobilier W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=161.13647, y[0]=1479.668, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=16698889, downTime=16695116, deviceId=0, source=0x1002 }
<p> </p>, reference=FFV0593, type=Apartment, numberOfRooms=Studio, livingArea=49sqm, terraceArea=-, building=Le Montaigne, district=Carré d'Or, parking=null, cellar=null, typeTransaction=Ԁt、��Fo, city=null, country=null, date created=2014-03-12 17:48:49, date last modified=2016-07-12 10:09:30]
07-13 13:27:36.366 1613-1613/com.example.adam_jaamour.cfimmobilier W/Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
07-13 13:27:36.836 1613-1623/com.example.adam_jaamour.cfimmobilier W/art: Suspending all threads took: 12.863ms
07-13 13:27:36.848 1613-1623/com.example.adam_jaamour.cfimmobilier I/art: Background sticky concurrent mark sweep GC freed 12227(1070KB) AllocSpace objects, 3(52KB) LOS objects, 2% free, 41MB/42MB, paused 13.974ms total 66.456ms
07-13 13:27:36.952 1613-1619/com.example.adam_jaamour.cfimmobilier W/art: Suspending all threads took: 19.437ms
07-13 13:27:37.062 1613-1623/com.example.adam_jaamour.cfimmobilier W/art: Suspending all threads took: 9.523ms
07-13 13:27:37.071 1613-1623/com.example.adam_jaamour.cfimmobilier I/art: Background sticky concurrent mark sweep GC freed 2527(286KB) AllocSpace objects, 17(812KB) LOS objects, 0% free, 43MB/43MB, paused 9.952ms total 80.879ms
07-13 13:27:37.125 1613-1701/com.example.adam_jaamour.cfimmobilier E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa2329c20
07-13 13:27:37.132 1613-1701/com.example.adam_jaamour.cfimmobilier D/OpenGLRenderer: endAllStagingAnimators on 0xa20b6880 (ListView) with handle 0xb3fec540
最佳答案
我认为您获取错误数据的问题在于,您获取的数据是基于从不同数据集中单击的项目,然后是适配器基于其 View 的内容(这两个数据集可能包含相同的内容)数据,但顺序不同)。
在这里,您正在从 json 构建数据集:
//for each where we get back values from sting set, then convert to product
for (String id : myJson) {
StackProduits savedProduct = gson.fromJson(id, StackProduits.class);
listProduits.add(savedProduct);
}
adapterFavoris = new ProduitsAdapter(getApplicationContext(), -1, listProduits);
produitFavorisListView.setAdapter(adapterFavoris);
在您的 OnItemClickListener 内部,根据您的方法签名,您正在从文件中检索数据:
//Set the click listener to launch the browser when a row is clicked.
produitFavorisListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
Intent intentProduitFavorisDetail = new Intent(Favoris.this, ProduitDetail.class);
StackProduits ProduitFavoris = ProduitsXmlPullParser.getStackProduitFromFile(Favoris.this).get(pos);
intentProduitFavorisDetail.putExtra("produit", ProduitFavoris);
startActivity(intentProduitFavorisDetail);
}
});
数据可以以不同的顺序存储,这可以解释为什么当您选择某些项目时会选择另一个项目信息。一种简单的测试方法是在 onItemClick 中放置一条日志语句,以打印出列表项的字符串表示形式。
如果这确实是您的问题,一个可能的解决方案是在您对 onItemClick 内部适配器的引用上调用 ProduitsAdapter.getItem() 以获取对应于“pos”的实际项目。
关于java - Android:ListView 项目点击无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38349390/
自从我 faced an issue由于背景图片对于不同分辨率的内容来说太短,我尝试将背景分成 3 部分并自动拉伸(stretch)中间部分以相应地填充顶部和底部图像之间的空间。不幸的是我没能在 CS
我从去年开始就在我的程序中运行这个函数(Linux 和 Windows)。 现在我需要实现一个新功能,我的新构建不再运行。 我还有其他使用 POST 的 CUrl 函数,结果是一样的:没问题,但我的
在评估函数应用方面,Haskell 是只支持普通降阶还是也支持应用降阶?我是否认为正常顺序是 Haskell 惰性的原因? 最佳答案 GHC 运行时不使用术语缩减策略,因为那会非常低效。事实上,GHC
怎么来的multi使用多处理池对多个“进程”上的数据进行分段和处理的函数比仅调用 map 慢(8 秒)。功能(6 秒)? from multiprocessing import Pool import
假设我正在渲染一个 3d GL_TRIANGLE。该对象需要 3 个顶点才能定义:A、B、C。我将此类数据放入缓冲区并通过 glVertexAttribPointer 将其绑定(bind)到着色器。
我有一个字体的三个文件,普通的,粗体的和浅色的。由于 font-weight:light 不存在,我该如何在 font-face 上设置 light 呢? 顺便问一下,font-weight:ligh
我是 C 的新手,我似乎无法弄清楚什么似乎是一个非常简单的指针问题。我的程序将行号添加到文件中。它逐行读入文件,然后在每行的开头添加一个行号。它在每个文件上都可以正常工作,如下所示: soccer@s
我有以下代码,我不确定为什么当它命中 Myclass 的析构函数时我会收到堆损坏检测错误。我相信我正在正确地释放内存?? #include #include using namespace std
有什么方法可以将“正常”数学符号解释为逆波兰符号 (RPN)..? 例如1) 2 + 3*4 - 1 = 234*+1-2) 5 (4-8) = 548- 你可以假设遵循 BODMAS 规则并且必须首
http://www.ergotopia.de/ergonomie-shop/ergonomische-kissen/orthopaedisches-sitzkissen的手机页面应该看起来像右边(检
我正在 Phonegap/Cordova 中构建一个应用程序。应用目前相当简单,但确实需要网络状态和地理定位插件才能工作。 到目前为止,我已经在 Android 上开发了该应用程序(目前它仅由一些基本
我一整天都在做这个,但没有运气 我设法在一行 TfidfVectorizer 中消除了问题 这是我的工作代码 from sklearn.feature_extraction.text import C
也许有人看到一个错误,问题是当我按btn2 (button 2)和btn3 (button 3)应用程序crashes时,但操作仍然有效,即video正在运行并且PDF打开,而button 1正常工作
我正在开发一个应用程序。它的第一页是登录屏幕。成功登录后,我想将用户带到选项卡式 Activity 。我怎样才能在安卓中做到这一点?谢谢 最佳答案 在 Android 中,启动 Activity 是通
我不确定我在这里做错了什么。 :normal! I### 当我对一个单词执行此命令时,我想要的最终结果是: ### word 但是我得到了这个: ###word 最佳答案 Vim 的 :normal是
我必须将 2 个静态矩阵发送到分配动态矩阵的函数,将矩阵 1 乘以矩阵 2,并返回新矩阵的地址。请注意,COMM 很常见。 我尝试删除 free_matrix 行,它工作正常。 void main()
我在我的一个项目中使用 Gnome libglib 并遇到了一个奇怪的错误。我可以输入 GList 的元素数量看起来仅限于 45 个。在第 45 个元素处,它给出了此错误 40 counter 41
我正在尝试获取“顶级”HWND 的尺寸。即,我想要 Firefox/Windows 资源管理器等的主 HWND 的当前尺寸。窗口。如果窗口最小化, GetWindowRect() 将不起作用。 Get
相同的标题:什么是索引 - 正常 - 全文 - 唯一? 最佳答案 普通索引用于通过仅包含行数据的切片或散列来加速操作。 全文索引向数据库的全文搜索 (FTS) 引擎指示它应该将数据存档在给定字段中,以
我正在使用 EnumParser来自 here它在 VC++ 中编译得很好,但是使用 gcc 我有这样的错误: ./Terminator.o: In function `EnumParser::Enu
我是一名优秀的程序员,十分优秀!