我正在尝试写出一个3d对象的坐标,但我不确定如何列出它.
到目前为止我有:
class threed:
def __init__(self,length,width,height):
self.h =height
self.l = length
self.w = width
self.f=0
self.lwh = (length,width,height)
for i in range(1,3):
for j in range(1,3):
for k in range(1,3):
coordinates=threed(i,j,k)
Run Code Online (Sandbox Code Playgroud)
问题是我的函数每次都重写变量坐标,所以我不能访问坐标(1,1,1).
请注意,上面是2x2x2对象.
如何有效地编写它以便我可以根据需要引用任何坐标?
我正在使用LinearLayout,因为这是我可以使用layout_weight的唯一方法,而且我不熟悉在RelativeLayout中均匀对齐textviews.(我是android新手).我正在创建一个日历应用程序,似乎无法弄清楚如何在我的7个文本视图下面获取textview.(7个textviews是一周中的几天).他们最终在同一行显示所有内容.
如何获得7天以下的最终文本视图?请注意我在stackoverflow上搜索了这个问题,但我没有找到任何对我有意义或工作的东西.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="top" >
<TextView
android:id="@+id/day1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/day1"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/day2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/day2"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/day3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/day3"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/day4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/day4"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/day5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/day5"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/day6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/day6"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/day7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/day7"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="a text string below" …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的 PagerAdapter,由于某种原因,当滚动到位置 2 时,它会删除位置 0 和 1 处的视图。
具体来说,当我第一次运行该应用程序时,有 3 个视图。我滚动到位置 2,位置 1 的视图将会消失。视图 0 仍然存在。如果我滚动到视图 0,然后返回到视图 2,然后再次返回到视图 0,视图 0 会突然消失。我再次执行相同操作,实际上可以看到视图 0 被实例化并立即被销毁。
这里发生了什么?
主要活动
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final MyPagerAdapter adapter = new MyPagerAdapter(this);
final ViewPager myPager = (ViewPager) findViewById(R.id.mypanelpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(1);
}
public class MyPagerAdapter extends PagerAdapter {
private Context ctx;
Calendar c = Calendar.getInstance();
int month = c.get(Calendar.MONTH);
int year = c.get(Calendar.YEAR);
ViewGroup collection;
public MyPagerAdapter (Context ctx){ …Run Code Online (Sandbox Code Playgroud) 可能重复:
如何通过单击对话框外部来关闭对话框?
如何在弹出窗口外单击以解除它?
这是我的代码:
cell.setOnClickListener(new OnClickListener(){
/*This code is in a separate class so I needed to use ctx as context
*and the string "layout_inflater" because it was not recognizing
*LAYOUT_INFLATER_SERVICE*/
@Override
public void onClick(View arg0) {LayoutInflater layoutInflater =
(LayoutInflater)ctx.getSystemService("layout_inflater");
View popupView = layoutInflater.inflate(R.layout.popup_window, null);
final PopupWindow popupWindow = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
popupWindow.showAtLocation(newParentLayout, Gravity.CENTER, 0, 0);
}
Run Code Online (Sandbox Code Playgroud)
我也试过添加所有这些但没有结果.
popupWindow.setTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
Drawable bg = ctx.getResources().getDrawable(R.drawable.popup_bg);
popupWindow.setBackgroundDrawable(bg);
Run Code Online (Sandbox Code Playgroud)
我没有想法.有帮助吗?
编辑添加:主要布局是ViewPager/PagerAdapter,如果这会影响任何事情?
我目前正在使用以下代码向用户的Facebook好友发送邀请.但是一旦运行该功能,会弹出一个确认对话框,我必须确认我想将请求发送给我的朋友.我想跳过这个额外的步骤.有没有办法避免这个确认对话框?
FB.ui({method:'apprequests', message:'would like you to try out our app!', to: ids});
Run Code Online (Sandbox Code Playgroud) 我正在创建一个函数来过滤我的 javascript 对象。
function filter(array,filterName,filterCondition,filterParameter){
for(var i=0; i< array.length;i++){
if(array[i][filterName] -<convert FilterCondition here>- filterParameter){
}
}
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想像这样使用它:
filter(anArray,"age",">",10)
Run Code Online (Sandbox Code Playgroud)
是否可以在我的 if 语句中将字符串比较运算符转换为真正的运算符?
我知道如何在线查找答案,用Java中的参数打开一个exe程序.但是我的具体捷径对我来说有点复杂.
我正在尝试打开一个具有以下目标的快捷方式:
C:\Windows\System32\javaw.exe -cp jts.jar;total.2012.jar -Dsun.java2d.noddraw=true -Dswing.boldMetal=false -Dsun.locale.formatasdefault=true -Xmx768M -XX:MaxPermSize=128M jclient/LoginFrame C:\Jts
在我的程序中,我将分割位置和我认为的参数分开.但是,当我运行程序时,我收到错误'Could not create Java Virtual Machine, Program will Exit'.能够更好地了解最新情况的人能解释我可能做错了什么,或者指出我可以阅读的方向吗?
String location = "C:\\Windows\\System32\\javaw.exe";
String p1="-cp jts.jar;total.2012.jar";
String p2="-Dsun.java2d.noddraw=true";
String p3="-Dswing.boldMetal=false";
String p4="-Dsun.locale.formatasdefault=true";
String p5="-Xmx768M";
String p6="-XX:MaxPermSize=128M";
String p7="jclient/LoginFrame" ;
String p8 = "C:\\Jts";
try {
Process p = new ProcessBuilder(location,p1,p2,p3,p4,p5,p6,p7,p8).start();
} catch (IOException ex) {
Logger.getLogger(Openprogramtest.class.getName()).log(Level.SEVERE, null, ex);
}
Run Code Online (Sandbox Code Playgroud) User.find_by_sql("...my statement here...").explain
导致错误undefined method explain for array...这对我来说非常有意义......
我没有使用rails.我正在使用sinatra虽然这应该没关系,因为命令来自activerecord我正在使用的宝石......
有什么建议?
我是新手做出反应,我正在为我的数据模型使用状态.
我有一个菜单,通过状态显示用户的个人资料图片.这是状态,因为用户可以更改他的个人资料图片.
我希望菜单从左侧滑入,最初隐藏.因此,我想将菜单的打开/关闭状态添加为状态.
我正在使用标准的Flux模式.
这是相关代码:
Menu.js
_onChange:function(){
this.setState({
opened: MenuStore.getMenuState(),
profilePicUrl: MenuStore.getUserPic()
})
},
componentDidMount:function(){
MenuStore.addChangeListener(this._onChange)
}
Run Code Online (Sandbox Code Playgroud)
MenuStore.js
MenuStore = assign({},EventEmitter.prototype,{
emitChange: function() {
this.emit(CHANGE_EVENT);
},
addChangeListener: function(callback) {
this.on(CHANGE_EVENT, callback);
},
...(rest of class not shown)
})
MenuStore.dispatchToken = Dispatcher.register(function(action) {
switch(action.type) {
case ActionTypes.RECEIVE_USER_DATA:
_userData = action.details;
MenuStore.emitChange();
break;
case ActionTypes.TOGGLE_MENU:
_opened = !_opened;
MenuStore.emitChange();
break;
default:
// do nothing
}
});
Run Code Online (Sandbox Code Playgroud)
Nav.js
toggleMenu:function(){
Actions.toggleMenu(); //in my actions.js it dispatches TOGGLE_MENU
}
render:function(){
return <div onClick={this.toggleMenu}>My Nav button</div> …Run Code Online (Sandbox Code Playgroud) 我有一个嵌套的模型,并希望做一些基本的管道.我的最终目标是删除任何嵌套映射,其中id == ""包含以下参数:
params = %{"name" => "OuterModelName", "InnerModel" => %{"0" => %{"id" => "2"}, "1" => %{"id" => "3"}, "2" => %{"id" => ""}}}
要删除id ==""以下管道工程:
blanksRemoved =
params
|> Map.update! "InnerModel", fn(innerMap) ->
Enum.filter(innerMap,fn{k,v} -> byte_size(v["id"]) !=0 end) end
Run Code Online (Sandbox Code Playgroud)
blanksRemoved现在是:
%{"name" => "OuterModelName", "InnerModel" => [{"0", %{"id" => "2"}}, {"1", %{"id" => "3"}}]}
注意innerModel变成了一个数组,所以我需要将该数组转换回结构.
asStruct =
blanksRemoved |> Map.update! "InnerModel", fn(innerMap) ->
Enum.into(innerMap,%{}) end
Run Code Online (Sandbox Code Playgroud)
这符合预期,我得到:
%{"name" => "OuterModelName", "InnerModel" => %{"0" => %{"id" => …
android ×3
activerecord ×1
elixir ×1
facebook ×1
java ×1
javascript ×1
python ×1
reactjs ×1
reactjs-flux ×1
ruby ×1