我正在尝试使用a RecyclerView作为横向ListView.我试图弄清楚如何突出显示所选项目.当我点击其中一个项目时,它会被选中并正确突出显示,但是当我点击另一个项目时,第二个项目会被旧项目突出显示.
这是我的onClick函数:
@Override
public void onClick(View view) {
if(selectedListItem!=null){
Log.d(TAG, "selectedListItem " + getPosition() + " " + item);
selectedListItem.setBackgroundColor(Color.RED);
}
Log.d(TAG, "onClick " + getPosition() + " " + item);
viewHolderListener.onIndexChanged(getPosition());
selectedPosition = getPosition();
view.setBackgroundColor(Color.CYAN);
selectedListItem = view;
}
Run Code Online (Sandbox Code Playgroud)
这是onBindViewHolder:
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
viewHolder.setItem(fruitsData[position]);
if(selectedPosition == position)
viewHolder.itemView.setBackgroundColor(Color.CYAN);
else
viewHolder.itemView.setBackgroundColor(Color.RED);
}
Run Code Online (Sandbox Code Playgroud) 我想要一些代码在后台持续运行.我不想在服务中这样做.还有其他方法吗?
我曾尝试Thread在我的课程中调用课程,Activity但我的Activity遗体在后台停留了一段时间然后停止了.该Thread课程也停止工作.
class testThread implements Runnable {
@Override
public void run() {
File file = new File( Environment.getExternalStorageDirectory(), "/BPCLTracker/gpsdata.txt" );
int i = 0;
RandomAccessFile in = null;
try {
in = new RandomAccessFile( file, "rw" );
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//String line =null;
while ( true ) {
HttpEntity entity = null; …Run Code Online (Sandbox Code Playgroud) 我尝试使用Imagebutton关闭当前片段.
我在Fragment-A中,当我点击按钮时它将转向Fragment-B.
当我点击Fragment-B上的按钮时,它将转向Fragment-C并关闭Fragment-B.
如果我单击Fragment-C上的后退按钮,它将返回Fragment-A.
我尝试过的代码如下所示
camera_album = (ImageButton) view.findViewById(R.id.camera_album);
camera_album.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
closefragment();
Fragment fragment = FileBrowserFragment.newInstance(null, null, null) ;
MainActivity.addFragment(LocalFileBrowserFragment.this, fragment) ;
}
});
private void closefragment() {
getActivity().getFragmentManager().beginTransaction().remove(this).commit();
}
Run Code Online (Sandbox Code Playgroud)
当我点击片段B的后退按钮时,它会转到Fragment-C.
但是当我单击Fragment-C上的后退按钮时,它不会返回到Fragment-A.它回到了空背景.如果我想回到Fragment-A,我必须再次单击后退按钮.
所以,似乎并没有完成当前片段的关闭.
如何像Android的后退按钮一样完成当前片段?
我使用cUrl(php)将项目代码以xml格式发送到Web服务.我在localhost中得到了正确的响应,但是什么时候服务器显示它
cURL错误(7):无法连接到主机
这是我的代码:
function xml_post($post_xml, $url)
{
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
// curl_setopt($ch, CURLOPT_PORT, $port);
$data = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if ($curl_errno > 0) {
echo "cURL Error ($curl_errno): $curl_error\n";
} else {
echo "Data received\n";
}
curl_close($ch);
echo $data;
}
Run Code Online (Sandbox Code Playgroud)
我将商品代码发送到计数器并从中获取详细信息.我尝试使用php 4+和php5 +两个版本,没有任何解决方案.
我试过了
DateFormat fmt = new SimpleDateFormat("MMMM dd, yyyy");
Date d = fmt.parse("June 27, 2007");
Run Code Online (Sandbox Code Playgroud)
Exception in thread "main" java.text.ParseException: Unparseable date: "June 27, 2007"
java文档说我应该使用四个字符来匹配完整的表单.我只能使用像"Jun"这样的缩写月份成功使用MMM,但我需要匹配完整的表格.
文本:对于格式化,如果模式字母的数量为4或更多,则使用完整形式; 否则,如果可用,则使用简短或缩写形式.对于解析,两种形式都被接受,与模式字母的数量无关.
http://java.sun.com/j2se/1.6.0/docs/api/java/text/SimpleDateFormat.html
嗨,我是Spring Security的新手,我正在进行登录,注销和会话超时功能.我通过引用此文档配置了我的代码,我的代码如下所示.
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/admin/**")
.access("hasRole('ROLE_USER')").and().formLogin()
.loginPage("/login").failureUrl("/login?error")
.usernameParameter("username")
.passwordParameter("password")
.and().logout().logoutSuccessUrl("/login?logout").and().csrf();
http.sessionManagement().maximumSessions(1).expiredUrl("/login?expired");
}
Run Code Online (Sandbox Code Playgroud)
重写AbstractSecurityWebApplicationInitializer类
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer {
@Override
public boolean enableHttpSessionEventPublisher() {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我还需要澄清我是否正确,如果它看起来不错,那么我需要在哪里设置会话超时.我是基于注释完全做到的.
当我使用连接对象调用createClob方法时,如下所示
Clob clob = con.createClob();
Run Code Online (Sandbox Code Playgroud)
抛出以下异常.
Caused by: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
at org.postgresql.Driver.notImplemented(Driver.java:659)
at org.postgresql.jdbc.PgConnection.createClob(PgConnection.java:1246)
at org.apache.commons.dbcp2.DelegatingConnection.createClob(DelegatingConnection.java:868)
at org.apache.commons.dbcp2.DelegatingConnection.createClob(DelegatingConnection.java:868)
Run Code Online (Sandbox Code Playgroud)
我正在使用带有JDK8的数据库PostgreSQL 9.6.2并使用commons-dbcp2连接池,并在pom.xml中添加了以下Postgres依赖项
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在类中createClob,createClob实现如下所示,它抛出了异常.
@Override
public Clob createClob() throws SQLException {
checkClosed();
throw org.postgresql.Driver.notImplemented(this.getClass(), "createClob()");
}
Run Code Online (Sandbox Code Playgroud)
解决此问题的解决方案或解决方法是什么?或者我们如何在Postgres查询中设置CLOB数据?
我一直在阅读Stackoverflow上的一些帖子,我没有找到一个好的解决方案,我想知道是否有可能检测到用户长时间按下电源按钮时试图关闭设备,我想知道你是否可以检测到该事件,并且让或者不显示出现的对话框(重启,关机等...)
我试过这个:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
Toast.makeText(MainActivity.this, event.getKeyCode(), Toast.LENGTH_SHORT).show();
return true;
}
Run Code Online (Sandbox Code Playgroud)
但它没有出现,它也应该作为一项服务工作,我的意思是应用程序可以打开或不打开显示吐司.
这就是我的方式 onCloseSystemDialog
//home or recent button
public void onCloseSystemDialogs(String reason) {
if ("globalactions".equals(reason)) {
Toast.makeText(PowerButtonService.this, "yaps", Toast.LENGTH_SHORT).show();
Intent i= new Intent(getBaseContext(), Demo.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(i);
//} else if ("homekey".equals(reason)) {
//home key pressed
//} else if ("recentapss".equals(reason)) {
// recent apps button clicked
}
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但只有当设备解锁时,设备被锁定时才会显示任何内容.
此外,我试图弄清楚如何在用户单击powerbutton时删除对话框我试过这个:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
Run Code Online (Sandbox Code Playgroud)
但如果我想再次展示它,我该怎么办呢?
我正在尝试使用本机代码构建android应用程序,所以我想测试ndk是否成功运行.当我尝试运行我的第一个hello world项目日志cat时,
01-21 23:30:06.780: E/AndroidRuntime(939): FATAL EXCEPTION: main
01-21 23:30:06.780: E/AndroidRuntime(939): java.lang.UnsatisfiedLinkError:
Native method not found: com.example.ndktesting.MainActivity.invokeNativeFunction:()Ljava/lang/String;
Run Code Online (Sandbox Code Playgroud)
我检查了一些stackoverflow的答案,但找不到我的答案.这是我的java代码,我正在使用android ndk r8d版本.
//ndktest.c
#include <string.h>
#include <jni.h>
extern "C"{
JNIEXPORT jstring JNICALL Java_com_example_ndktesting_ndktest_MainActivity_invokeNativeFunction(JNIEnv* env, jobject thiz)
};
JNIEXPORT jstring JNICALL Java_com_example_ndktesting_ndktest_MainActivity_invokeNativeFunction(JNIEnv* env, jobject thiz){
return (*env)->NewStringUTF(env, "Hello from native code!");
}
Run Code Online (Sandbox Code Playgroud)
这是我的MainActivity java代码
package com.example.ndktesting;
public class MainActivity extends Activity {
//declare the native code function - must match ndktest.c
private native String invokeNativeFunction();
public native String unimplementedinvokeNativeFunction();
// load the library …Run Code Online (Sandbox Code Playgroud) 我想向下滚动我的网页并使用此代码滚动页面,但它无法正常工作
public ViewBasketSentToMePageObject viewSlideShare() throws InterruptedException {
Thread.sleep(500l);
Actions action1 =new Actions(getDriver());
action1.keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u0030')).build().perform();
List<WebElement> function = getDriver().findElements(By.xpath("//a [@ng-click='onItemClick()']"));
function.get(13).findElement(By.xpath("//img [@ng-src='resources/images/slideshare-icon-small.png']")).click();
return getFactory().create(ViewBasketSentToMePageObject.class);
}
Run Code Online (Sandbox Code Playgroud)
寻求帮助
android ×5
java ×4
android-ndk ×1
curl ×1
events ×1
jdbc ×1
php ×1
postgresql ×1
selenium ×1
session ×1
spring ×1
spring-mvc ×1
xml ×1