小编ab1*_*b11的帖子

Android:如何在单选模式ListView中选择更改时收到通知?

我希望我的ListView突出显示所选项目,直到选择更改为止.此外,我希望在选择更改时收到通知.

为了完成第一项任务,我打电话给list.setChoiceMode(ListView.CHOICE_MODE_SINGLE).

我不知道如何完成第二次.当单击列表项,我OnItemSelectedListener从不通知,并因为受OnItemClick事件发生的时候,我的ListView的checkedItem已修改OnItemClickListener是不够的,所以如果点击事件导致中进行选择,我不能区分(这是已点击的项目已被选中的可能性/可能性.

一种选择是将当前检查的索引存储在成员变量中,我可以使用它来确定click事件是否对应于选择更改.但是这个丑陋而且,对于这种选择模式,当然有一种方法可以用提供的监听器来做到这一点吗?

public class Temp extends Activity implements OnItemClickListener, OnItemSelectedListener
{
    ListView mView;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        List<String> strings = new ArrayList<String>();
        strings.add("1");
        strings.add("2");
        strings.add("3");
        strings.add("4");
        strings.add("5");


        mView = new ListView(this);
        mView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        mView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1, strings));
        mView.setItemChecked(0, true);

        mView.setOnItemClickListener(this);
        mView.setOnItemSelectedListener(this);

        setContentView(mView);
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
    {
        //this never gets called
        Log.e("item selected", ""+position);
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent)
    {
        Log.e("nothing seleted", "");
    }

    @Override …
Run Code Online (Sandbox Code Playgroud)

android

2
推荐指数
1
解决办法
2219
查看次数

Android:如何使用压缩状态drawable为焦点状态绘制ImageButton

我试图实现一种效果,一旦按下,一个ImageButton绘制"按下"的橙色背景,直到它失去焦点(触摸其他东西).

StateListDrawable似乎适用于这种情况,因为它允许我定义如何为聚焦状态绘制背景.如果我可以简单地定义应该使用按下的drawable绘制背景,那么对于聚焦状态会很棒.但是,我认为没有办法引用默认的"按下"drawable.

关于如何实现这种效果的任何建议?

android background button

1
推荐指数
1
解决办法
3568
查看次数

Android:如何关闭显式显示的软键盘?

我正在显示一个文本输入对话框,如果没有打开硬键盘,我想自动显示软键盘。为了让它在我的三星 Galaxy Tab 上显示,我不得不使用 SHOW_FORCED 标志,SHOW_IMPLICIT 标志不起作用。另外,在关闭对话框时,如果我强制显示键盘,我想关闭键盘。但是,我在下面使用的代码不会关闭 Galaxy Tab 上的键盘;我认为这是因为我使用了 Explicit 标志来显示。

    /* from the dialog constructor*/

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.restartInput(mEditText);

    //only display if there is no hard keyboard out 
    Configuration config = getResources().getConfiguration();
    if (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES)
    {
      mForcedKeyboardDisplay = true;
      imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }


    /* from the onDismiss() method*/

    //if we previously forced keyboard display, force it to close
    if (mForcedKeyboardDisplay)
    {
       InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
       imm.restartInput(mEditText);

       imm.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
       //this doesn't work either 
       //imm.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
       //nor does this …
Run Code Online (Sandbox Code Playgroud)

android android-softkeyboard

1
推荐指数
1
解决办法
4757
查看次数

Android:如何截断TableLayout中的TextView?

我在TableLayout的列中有一个TextView.如果TextView的文本比列可以容纳的长,我希望TextView截断和椭圆化,但它只是拉伸列并破坏我的布局.我发现TextView截断的建议都没有用,我假设这是由于表.有什么建议?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </TextView>
    <RelativeLayout  
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <ImageView 
            android:id="@+id/Icon"
            android:src="@drawable/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </ImageView>
        <TextView 
            android:id="@+id/Value"
            android:layout_toRightOf="@id/Icon"
            android:text="very long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long string"
            android:inputType="text"
            android:maxLines="1"
            android:ellipsize="end"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </TextView>
    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

*编辑:表格代码:

int fiveDip = convToDip(5, getContext());

Table table = new TableLayout(getContext());
table.setPadding(fiveDip, fiveDip, …
Run Code Online (Sandbox Code Playgroud)

android

1
推荐指数
1
解决办法
2326
查看次数

关于在 junit 中使用 H2 的一些说明?

下面给了我:

org.h2.jdbc.JdbcSQLException:表“FOO”已经存在;SQL语句

这让我感到困惑,并希望得到一些澄清。

H2 服务器何时启动/关闭,由getConnectionclose

为什么会already exists发生?当 H2 服务器启动时,模式是否从以前的会话中持久化?

在 H2 中设置测试模式和数据集以用于数据库单元测试的任何最佳实践建议?

public class MyTest {
    @Before
        public void setUp() throws ClassNotFoundException, SQLException {
            try {
                   Class.forName("org.h2.Driver");
                    Connection conn = DriverManager.getConnection("jdbc:h2:~/test;MODE=Oracle", "sa", "");
                    // add application code here


                    Statement statement =conn.createStatement();
                    statement.execute("create table foo (id integer)");
                    conn.commit();

                    ResultSet rs = statement.executeQuery("select * from foo");
                    if (rs.next()) {
                            System.out.println(rs.getString("id"));
                    }

                    statement.execute("insert into foo (id) values (5)");
                    conn.commit();

                    rs = statement.executeQuery("select * from foo");
                    if (rs.next()) …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
1966
查看次数

如何从单个ActiveRecord列获取值列表?

像这样的代码

my_id_results = MyTable.select("some_id").as_json
Run Code Online (Sandbox Code Playgroud)

返回一个哈希数组,每个哈希都包含idsome_

[
    {id => nil, some_id => 1},
    {id => nil, some_id => 2},
    {id => nil, some_id => 3}
]
Run Code Online (Sandbox Code Playgroud)

我可以将此数组映射到这样的ID列表

my_ids = []
my_id_results.each do |my_id_result|
  my_ids.push my_id_result['some_id']
end
Run Code Online (Sandbox Code Playgroud)

对于这种情况,当我在寻找单个列的值列表时,是否可以直接从ActiveRecord返回平面数组?

ruby ruby-on-rails

1
推荐指数
1
解决办法
49
查看次数

如何使用流来展平和分组此HashMap?

给定字母到数字的映射,我想返回一个字符串列表,其中每个字符串都是以逗号分隔的列表,这些列表按字母的关联编号分组。

对于这张地图

    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("A", 1);
    map.put("B", 2);
    map.put("C", 4);
    map.put("D", 1);
    map.put("E", 1);
    map.put("F", 2);
Run Code Online (Sandbox Code Playgroud)

我想返回一个包含以下内容的列表:

"A,D,E" "B,F", "C"
Run Code Online (Sandbox Code Playgroud)

有什么建议可以使用1.8流功能实现吗?

java java-8 java-stream

1
推荐指数
1
解决办法
109
查看次数

要记录什么来调试错误 [ERR_HTTP_HEADERS_SENT]?

在 Express 控制器功能中,我遇到了此错误Error [ERR_HTTP_HEADERS_SENT]res.json()如果已在对象上设置标头,则当我调用时会发生这种情况res。但是,我在函数(或中间件)中没有看到可以在调用之前设置标头的位置res.json()

为了调试这个错误的原因,我想我可以添加一些日志记录。在调用 之前res.json,我可以检查标头是否已设置,如果是,则记录有关设置者的一些信息。

async function get(req, res) {

  ... 

  if (res._header) {
    logger.debug(...);
  }

  res.json(...);
Run Code Online (Sandbox Code Playgroud)

不幸的是,我在要记录的对象中没有看到任何有用的res信息,也没有看到任何表明为什么/如何设置标头(或谁设置了标头)的消息。对于我可以记录哪些内容来调试此问题有什么建议吗?或者其他调试建议?

node.js express

1
推荐指数
1
解决办法
239
查看次数

如何使用类的类型作为参数?

我如何编写和调用boolean doInstanceof(...)接受Object o和类型的方法,t如果o是实例t,则返回true,否则返回false.

就像是:

boolean doInstanceof(Object o, type t)
{
    return o instanceof t;
}

//called like
boolean isInstance = doInstanceof(new MyClass(), MyClass.type())
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
81
查看次数

使用maven,为pom添加依赖并下载它?

这是一个非常简单的问题,但我搜索了一个解决方案,没有什么对我有用.我将以下内容添加到我的pom.xml中,但无法导入org.apache.commons.csv.CSVParser我的class.当我运行mvn install时,我得到以下输出.

<dependencies> 
      ....

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-csv</artifactId>
        <version>1.1.1-SNAPSHOT</version>
    </dependency>

    ....
 </dependencies>
Run Code Online (Sandbox Code Playgroud)

D:\java\my_project>mvn install    
[INFO] Scanning for projects...    
[INFO] Building my_project 1.0-SNAPSHOT

[WARNING] The POM for org.apache.commons:commons-csv:jar:1.1.1-SNAPSHOT is missing, no dependency information available

[INFO] BUILD FAILURE    

[INFO] Total time: 0.644 s    
[INFO] Finished at: 2015-07-21T08:46:47-04:00    
[INFO] Final Memory: 8M/245M    

[ERROR] Failed to execute goal on project my_project: Could not resolve depen dencies for project com.myproject:artifact:jar:1.0-SNAPSHOT: Could not find artifact org.apache.commons:commons-csv:jar:1.1.1-SNAPSHOT -> [Help 1]  
[ERROR] To see the …
Run Code Online (Sandbox Code Playgroud)

java maven

-1
推荐指数
1
解决办法
850
查看次数