我想在主屏幕中放置一个textView,我需要选框效果
public class MainWidget extends AppWidgetProvider {
int a;
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;
String[] s={"woddfdfdfdfdfdffffffffffffffffffffffffffffffff","dd","ddd","ffff"};
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new WlanTimer(context, appWidgetManager), 100, 50000);
}
private class WlanTimer extends TimerTask {
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;
public WlanTimer(Context context, AppWidgetManager appWidgetManager) {
this.appWidgetManager = appWidgetManager;
remoteViews = new RemoteViews(context.getPackageName(), R.layout.marketwidget_main);
thisWidget = new ComponentName(context, MainWidget.class);
}
@Override
public void run() {
a=(int) (Math.random()*3);
remoteViews.setTextViewText(R.id.TextView_marketwidget_main_marketmessage,s[a]);
appWidgetManager.updateAppWidget(thisWidget, remoteViews);
} …Run Code Online (Sandbox Code Playgroud) public class testScreenRotation extends Activity {
/** Called when the activity is first created. */
private int mRuntimeOrientation;
private boolean mDisableScreenRotation=true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRuntimeOrientation = this.getScreenOrientation();
setContentView(R.layout.main);
}
protected int getScreenOrientation() {
/*
Display display = getWindowManager().getDefaultDisplay();
int orientation = display.getOrientation();
if (orientation == Configuration.ORIENTATION_UNDEFINED) {
orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_UNDEFINED) {
if (display.getWidth() == display.getHeight())
orientation = Configuration.ORIENTATION_SQUARE;
else if(display.getWidth() < display.getHeight())
orientation = Configuration.ORIENTATION_PORTRAIT;
else
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
}
return …Run Code Online (Sandbox Code Playgroud) 我想将图像插入editText,我的代码是:
CharSequence charSeq= editText.getText()+" ";
SpannableString ss2 = new SpannableString(charSeq);
Drawable d2 = holder.image.getDrawable();
d2.setBounds(0, 0, d2.getIntrinsicWidth(), d2.getIntrinsicHeight());
ImageSpan span2 = new ImageSpan(d2, ImageSpan.ALIGN_BASELINE);
ss2.setSpan(span2,charSeq.length()-1, charSeq.length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
editText.setText(ss2,BufferType.SPANNABLE);
Run Code Online (Sandbox Code Playgroud)
我的代码可以运行,但我有一些不错的经验,我想修改:
1:你知道什么时候使用ss2.setSpan()方法,图像可以替换字符,我只想插入新图像,不要想图像替换字符.
2:你知道我的方法包括"editText.getText()+"";",我添加一些额外的空间,以便图像可以插入最后的CharSequence.如何不需要添加一些额外的,图像也插入最后的CharSequence.
3.当我将图像插入CharSequence的最后一个时,光标不在最后,它出现在CharSequence的前面.如何将光标放在图像后面.
4.i想在不同的CharSequence中不断插入图像,怎么办?
我的问题很多,我希望你能帮助我,非常感谢你.
int w = width ;
int h =height ;
Log.i("SopCast", "w:"+w+"-----h:"+h);
int b[]=new int[(int) (w*h)];
int bt[]=new int[(int) (w*h)];
IntBuffer buffer=IntBuffer.wrap(b);
buffer.position(0);
GLES20.glReadPixels(0, 0, w, h,GLES20.GL_RGBA,GLES20.GL_UNSIGNED_BYTE, buffer);
for(int i=0; i<h; i++)
{
//remember, that OpenGL bitmap is incompatible with Android bitmap
//and so, some correction need.
for(int j=0; j<w; j++)
{
int pix=b[i*w+j];
int pb=(pix>>16)&0xff;
int pr=(pix<<16)&0x00ff0000;
pix1=(pix&0xff00ff00) | pr | pb;
bt[(h-i-1)*w+j]=pix1;
}
}
Bitmap inBitmap = null ;
if (inBitmap == null || !inBitmap.isMutable()
|| inBitmap.getWidth() != w …Run Code Online (Sandbox Code Playgroud) 我想ListView在Android中使用过滤器.我找到了这个链接但我这样做我无法获得过滤效果.谁能告诉我有什么问题?我的代码是
public class testListViewFilter extends ListActivity {
/** Called when the activity is first created. */
private EditText filterText = null;
ArrayAdapter<String> adapter = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
filterText = (EditText) findViewById(R.id.search_box);
filterText.addTextChangedListener(filterTextWatcher);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
mStrings));
adapter = new ArrayAdapter<String> (this,
android.R.layout.simple_spinner_item, mStrings);
}private TextWatcher filterTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, …Run Code Online (Sandbox Code Playgroud) 我在textView中有一个字符串:
<TextView
android:id="@+id/comment_concent"
android:maxLines="2"
android:textColor="#FFCD3333"
android:ellipsize="end"
android:layout_marginRight="5dip"
android:layout_width="210dip"
android:layout_height="50dip"
android:textSize="15sp"
android:text="aaddadadddddddddddddddddddddddddddddddddddddadddddddd"/>
Run Code Online (Sandbox Code Playgroud)
有时文本只有"addadaddad",换句话说字符串长度不固定,所以如果字符串太长,你知道结尾是显示"...",我的问题是如何知道字符串如果结束"...",如果字符串以"..."结尾,我将调用其他方法来显示整个字符串.
我使用以下代码在组tableview标题标题设置标题,但默认文本是AlignmentLeft,如何AlignmentCenter?
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if(section==0){
return NSLocalizedString(@"more_titlehead_one", nil);
}else if (section==1){
return NSLocalizedString(@"more_titlehead_two", nil);
}else{
return NSLocalizedString(@"more_titlehead_three", nil);
}
}
Run Code Online (Sandbox Code Playgroud) 我知道[[UIDevice currentDevice] uniqueIdentifier]被拒绝了,我用过:
- (NSString *) uniqueDeviceIdentifier{
NSString *macaddress = [[UIDevice currentDevice] macaddress];
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSString *stringToHash = [NSString stringWithFormat:@"%@%@",macaddress,bundleIdentifier];
NSString *uniqueIdentifier = [stringToHash stringFromMD5];
return uniqueIdentifier;
}
Run Code Online (Sandbox Code Playgroud)
如果我的方法未经Apple批准,我可以使用哪种方法获取唯一标识符?
//initialize the people data list
- (void)initializePeopleListFromJson:(CLLocationCoordinate2D)coordinate auraId:(NSString *)auraId
{
//initialize the NSMutableArray list
self.peopleList = [[NSMutableArray alloc] init];
//retrieve the coordinate of myself
//NSString *myCoordinate = [NSString stringWithFormat:@"%f,%f", coordinate.latitude, coordinate.longitude];
NSString *myCoordinate = @"31.2,121.6";
NSString *url = [NSString stringWithFormat:@"%@%@%@%@", @"http://services.portaura.mobi/AuraMesh/auraFinder/findPeoples?ll=", myCoordinate, @"&source=tencent,netease,kaixin&myAuraId=", auraId];
NSLog(@"*********** %@", url);
//retrieve the people list from web service
NSDictionary* result = [NSDictionary dictionaryWithContentsOfJSONURLString:url];
NSArray *peopleListFromJson = [result objectForKey:@"data"];
Run Code Online (Sandbox Code Playgroud)
// NSLog(@"peopleList:%@",peopleListFromJson);
People *people;
UserProfile *userProfile;
NSDictionary *geoFromJson;
NSDictionary *profileFromJson;
for (NSDictionary *peopleFromJson in peopleListFromJson)
{ …Run Code Online (Sandbox Code Playgroud) 我的json:
{
"name": "notification",
"args": [
"{\"data\": [{\"foreignId\":\"BF7E9276D8607DA5916F796F9F1B9743_2\",\"id\":\"\",\"img\":{\"small\":\"http://jiepang.com/static/img/icon-special-newbie.gif\"},\"poiId\":\"4fe133bb581f7129d6c3f2b3\",\"poiName\":\"Incubation Club Cafe - ICC\",\"source\":\"jiepang\",\"what\":\"aaaa?\",\"when\":\"\"}],\"size\":3,\"toWho\":[\"4ffa80c8e4b0f73fa2b758c9\"],\"type\":5,\"when\":\"2012-07-09T17:23:24Z\"}"
]
}
Run Code Online (Sandbox Code Playgroud)
我的代码:
NSDictionary* data=(NSDictionary *)[packet.data JSONValue];
NSString* str=[NSString stringWithFormat:@"%@",[data objectForKey:@"name"]];
txtview.text = [txtview.text stringByAppendingString:str];
NSData *jsonData = [packet.data dataUsingEncoding:NSUTF8StringEncoding];
__autoreleasing NSError* error = nil;
NSDictionary *resultdata = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
// NSDictionary* arr=[data valueForKeyPath:@"args.data"];
NSMutableDictionary *peopleListFromJson = [[NSMutableDictionary alloc] init];
peopleListFromJson = [resultdata valueForKeyPath:@"args.data"];
// NSArray *peopleListFromJson = [[result objectForKey:@"data"]objectForKey:@"list"];
if ( ![peopleListFromJson isKindOfClass:[NSArray class]] && peopleListFromJson!=nil) {
peopleListFromJson =[NSArray arrayWithObject:peopleListFromJson];
}
for (NSDictionary *peopleFromJson in …Run Code Online (Sandbox Code Playgroud)