我想在listview android中单击它时突出显示项目 的 Listview.xml
string connstring;
connstring = ConfigurationManager.ConnectionStrings["dbConn"].ConnectionString;
SqlConnection conn = new SqlConnection(connstring);
SqlCommand cmd = new SqlCommand("dbo.totalEarned", conn);
cmd.Parameters.Add(new SqlParameter("@enrollmentId", enrollmentId));
cmd.Parameters.Add(new SqlParameter("@totalEarned", null));
cmd.CommandType = System.Data.CommandType.StoredProcedure;
using (conn)
{
conn.Open();
double totalEarned = (double)cmd.ExecuteScalar();
}
这是项目设计
的 ListItem_text.xml
<it.sephiroth.android.library.widget.HListView
android:id="@+id/submenu_button"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp"/>
listview_selector.xml
<TextView
android:id="@+id/submenu_layout_button"
android:layout_width="130dp"
android:layout_height="70dp"
android:background="@drawable/listview_selector"
android:text="Soupsdfsddfsdf"
android:textColor="#fff"
android:textSize="18dp"
android:layout_margin="20dp"
android:padding="10dp"
android:gravity="center_horizontal|center_vertical"/>
Fragment.class
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:drawable="@drawable/item_click_button1"/>
<item
android:drawable="@drawable/submenu_bg" />
</selector>
答案 0 :(得分:2)
put adapter.notifydatasetchanged();
在view.setSelected(true)之后;这一行
答案 1 :(得分:0)
试试这个。
在您的活动类中使用listview.setOnClickListener()
可以正常使用