Skip to content

Instantly share code, notes, and snippets.

View Reacoder's full-sized avatar

赵小龙_同学 Reacoder

  • shanghai china
View GitHub Profile
@Reacoder
Reacoder / edittext.java
Created August 5, 2014 05:27
EditText onClick event is not triggering
When a user interacts with a UI element the various listeners are called in a top down order. (For example: OnTouch -> OnFocusChange -> OnClick.) If a listener has been defined (with setOn...Listener) and it consumes this event: the lower priority listeners will not be called. By its nature the first time you touch an EditText it receives focus with OnFocusChangeListener so that the user can type. The action is consumed here therefor OnClick is not called. Each successive touch doesn't change the focus so the event trickles down to the OnClickListener.
Basically, you have three choices:
Set the focusable attribute to false in your XML:
android:focusable="false"
Now the OnClickListener will fire every time it is clicked. But this makes the EditText useless since the user can no longer enter any text...
Implement an OnFocusChangeListener along with the OnClickListener:
/* Clear all Fragments inside current adapter */
public class MyPagerAdapter extends FragmentPagerAdapter
{
private ArrayList<Fragment> fragments=new ArrayList<Fragment>();
//...some stuff
public void clearAll() //Clear all page
{
for(int i=0; i<fragments.size(); i++)
fragMan.beginTransaction().remove(fragments.get(i)).commit();
@Reacoder
Reacoder / modifyActionButton.java
Created July 30, 2014 08:40
动态改变actionbutton。
/* Called whenever we call invalidateOptionsMenu() */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
Logger.d("======== onPrepareOptionsMenu =========="+mSubscribed);
MenuItem item = menu.findItem(R.id.action_subscribe);
if (mSubscribed) {
item.setTitle(R.string.menu_unsubscribe);
item.setIcon(R.drawable.btn_actionbar_unsubscriptions);
} else {
item.setTitle(R.string.menu_subscribe);
@Reacoder
Reacoder / PagerAdapter.java
Created July 30, 2014 02:54
fragment 中 包含 fragment, 还有 indicator。
package com.ilegendsoft.toprankapps.musictube.adapters;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import com.toprankapps.musictube4.R;
import com.ilegendsoft.toprankapps.musictube.fragments.HotArtistFragment;
import com.ilegendsoft.toprankapps.musictube.fragments.PopularFragment;
@Reacoder
Reacoder / TableLayout.xml
Created July 30, 2014 02:45
TableLayout 每列的宽度相等。
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp" >
<TableRow>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
@Reacoder
Reacoder / fragmentMenu.java
Created July 29, 2014 07:59
fragment 中显示action button。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:musictube="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/action_play"
android:icon="@drawable/btn_all_actionbar_play"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
android:title="@string/action_play"
musictube:showAsAction="always|withText"/>
@Reacoder
Reacoder / AndroidStudio
Created July 26, 2014 03:19
AndroidStudio key map.
*F1 显示声明。
Shift+F1 浏览器查看声明
*Command+B 进入源码。
Command+F12 显示类中的所有方法。
*Option+Enter 修复提示,还可以提取字符串到value中。
@Reacoder
Reacoder / replaceUrlPara.java
Created July 25, 2014 05:24
替换url 中的某个参数。
protected static String getRealPlayUrl(String playUrlWithTempSig, String sig) {
// http://r13---sn-a5m7ln7r.googlevideo.com/videoplayback?
// sparams=gcr%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&source=youtube
// &signature=74A5A84D017C326B86FBB2515BD6C00BCD85133A.E1CB6514CD41B99045FF236A3F7CF0F50F4AEC14&itag=22&key=yt5&mws=yes&gcr=cn&ms=au
// &ipbits=0&ratebypass=yes&expire=1406281956&upn=raAqucAppMU&id=o-AP5UIALOxGG5ae6zN-JNagnKvRQa_WtGXk8czf3NgFuW&mv=u&sver=3&ip=199.245.60.115
// &fexp=902408%2C924222%2C927622%2C934024%2C934030%2C941431%2C945066%2C946023&mt=1406260337&initcwndbps=1093375
String realUrl = playUrlWithTempSig.replaceFirst("signature="+"[^&]*", "signature="+sig);
System.out.println("======= realUrl ======="+realUrl);
return realUrl;
}
@Reacoder
Reacoder / moveUserInfoLayoutInY.java
Created July 24, 2014 10:00
动态改变margin 布局。
private void moveUserInfoLayoutInY(int marginTop) {
MarginLayoutParams marginParams = new MarginLayoutParams(mUserInfoLayout.getLayoutParams());
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, marginTop, getResources().getDisplayMetrics());
marginParams.setMargins((int)mUserInfoLayout.getLeft(), (int)px, 0, 0);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams);
mUserInfoLayout.setLayoutParams(layoutParams);
}
@Reacoder
Reacoder / ListViewHeight.java
Created July 24, 2014 06:24
Android ListView fixed height item
short answer:
when inflating for convertView, instead of just
result = inf.inflate(R.layout.thread_item, null);
do
result = inf.inflate(R.layout.thread_item, parent, false);
explanation: